-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Queue Dynamo conversion to Typescript, and number of fixes #2603
Merged
dekkerglen
merged 14 commits into
dekkerglen:master
from
KaelenProctor:feature/dynamo-5
Feb 12, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
be615b4
Rename to ts.
KaelenProctor cff52f9
Convert FeaturedQueue to typescript.
KaelenProctor 1311422
Handle edge case of no featured cubes in the queue.
KaelenProctor 1b96f1c
Fix Rotate featured cubes confirmation model/alignment with backend
KaelenProctor 381a139
Fix adding feature cube in the Admin portal.
KaelenProctor 5c9156b
Fix returning of errors in rotateFeatured so that the UI is notified.
KaelenProctor 35c6983
Fix removing feature queue in the Admin portal.
KaelenProctor 0dcd64c
Remove unused method.
KaelenProctor 1f4b824
Typo.
KaelenProctor 0c16036
Remove the move action for the featured queue as it doesn't work for a
KaelenProctor 2c7cf07
Rename variable for clarity.
KaelenProctor 4a86ed7
Fix not awaiting async functions so error messages weren't accurate.
KaelenProctor e6f8f21
Correct property of result checked for success or fail.
KaelenProctor 0d16df8
Lint fixes.
KaelenProctor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export enum FeaturedQueueStatus { | ||
ACTIVE = 'a', | ||
INACTIVE = 'i', | ||
} | ||
|
||
export type NewFeaturedQueueItem = { | ||
cube: string; //Cube ID | ||
date: number; | ||
owner: string; //User id | ||
featuredOn: number | null; //Null indicates not yet featured | ||
}; | ||
|
||
export type FeaturedQueueItem = NewFeaturedQueueItem & { | ||
status: FeaturedQueueStatus; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { DocumentClient } from 'aws-sdk2-types/lib/dynamodb/document_client'; | ||
|
||
import { FeaturedQueueItem, FeaturedQueueStatus, NewFeaturedQueueItem } from '../../datatypes/FeaturedQueue'; | ||
import createClient, { QueryInput } from '../util'; | ||
|
||
const client = createClient({ | ||
name: 'FEATURED_QUEUE', | ||
partitionKey: 'cube', | ||
indexes: [ | ||
{ | ||
name: 'ByDate', | ||
partitionKey: 'status', | ||
sortKey: 'date', | ||
}, | ||
], | ||
attributes: { | ||
cube: 'S', | ||
date: 'N', | ||
status: 'S', | ||
}, | ||
}); | ||
|
||
module.exports = { | ||
getByCube: async (id: string): Promise<FeaturedQueueItem> => { | ||
return (await client.get(id)).Item as FeaturedQueueItem; | ||
}, | ||
put: async (document: NewFeaturedQueueItem): Promise<void> => { | ||
await client.put({ | ||
...document, | ||
status: FeaturedQueueStatus.ACTIVE, | ||
}); | ||
}, | ||
querySortedByDate: async ( | ||
lastKey?: DocumentClient.Key, | ||
limit = 36, | ||
): Promise<{ items?: FeaturedQueueItem[]; lastKey?: DocumentClient.Key }> => { | ||
//Using keyof .. provides static checking that the attribute exists in the type. Also its own const b/c inline "as keyof" not validating | ||
const statusAttr: keyof FeaturedQueueItem = 'status'; | ||
|
||
const query: QueryInput = { | ||
IndexName: 'ByDate', | ||
KeyConditionExpression: '#status = :status', | ||
ExpressionAttributeNames: { | ||
'#status': statusAttr, | ||
}, | ||
ExpressionAttributeValues: { | ||
':status': FeaturedQueueStatus.ACTIVE, | ||
}, | ||
Limit: limit, | ||
}; | ||
if (lastKey) { | ||
query.ExclusiveStartKey = lastKey; | ||
} | ||
const result = await client.query(query); | ||
|
||
return { | ||
items: result.Items as FeaturedQueueItem[], | ||
lastKey: result.LastEvaluatedKey, | ||
}; | ||
}, | ||
queryWithOwnerFilter: async ( | ||
ownerID: string, | ||
lastKey?: DocumentClient.Key, | ||
): Promise<{ items?: FeaturedQueueItem[]; lastKey?: DocumentClient.Key }> => { | ||
//Using keyof .. provides static checking that the attribute exists in the type. Also its own const b/c inline "as keyof" not validating | ||
const statusAttr: keyof FeaturedQueueItem = 'status'; | ||
const ownerAttr: keyof FeaturedQueueItem = 'owner'; | ||
|
||
const query: QueryInput = { | ||
IndexName: 'ByDate', | ||
KeyConditionExpression: '#status = :status', | ||
FilterExpression: '#owner = :owner', | ||
ExpressionAttributeNames: { | ||
'#status': statusAttr, | ||
'#owner': ownerAttr, | ||
}, | ||
ExpressionAttributeValues: { | ||
':status': FeaturedQueueStatus.ACTIVE, | ||
':owner': ownerID, | ||
}, | ||
}; | ||
if (lastKey) { | ||
query.ExclusiveStartKey = lastKey; | ||
} | ||
const result = await client.query(query); | ||
|
||
return { | ||
items: result.Items as FeaturedQueueItem[], | ||
lastKey: result.LastEvaluatedKey, | ||
}; | ||
}, | ||
batchPut: async (documents: FeaturedQueueItem[]): Promise<void> => client.batchPut(documents), | ||
createTable: async (): Promise<DocumentClient.CreateTableOutput> => client.createTable(), | ||
delete: async (id: string): Promise<void> => client.delete({ cube: id }), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the backend and frontend code, it is a number