Skip to content

Commit

Permalink
Fix bugs in createSynonyms
Browse files Browse the repository at this point in the history
- Fix incorrect table name
- Add missing check for zero length
- Merge some statements into a single line (stylistic, not a bug)
  • Loading branch information
lpsinger committed Mar 1, 2024
1 parent 3e6e0e1 commit cd28828
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions app/routes/_gcn.synonyms/synonyms.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,23 @@ import crypto from 'crypto'
*/
export async function createSynonyms(...synonymousEventIds: string[]) {
const uuid = crypto.randomUUID()
const db = await tables()
const client = db._doc as unknown as DynamoDBDocument

const writeRequests = synonymousEventIds
.filter((eventId) => Boolean(eventId))
.map((eventId) => ({
PutRequest: {
Item: { uuid, eventId },
},
}))
if (synonymousEventIds.length > 0) {
const db = await tables()
const client = db._doc as unknown as DynamoDBDocument
const TableName = db.name('synonyms')

const params = {
RequestItems: {
synonyms: writeRequests,
},
await client.batchWrite({
RequestItems: {
[TableName]: synonymousEventIds.map((eventId) => ({
PutRequest: {
Item: { uuid, eventId },
},
})),
},
})
}

await client.batchWrite(params)

return uuid
}

Expand Down

0 comments on commit cd28828

Please sign in to comment.