-
Notifications
You must be signed in to change notification settings - Fork 0
Allow querying and fulfilling purchases by email #379
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5177602
Add API route query purchases by email
devksingh4 d7de5f0
Fix valid calculation
devksingh4 eb1c8fe
Fix unit test
devksingh4 82e1a05
Fix coderabbit suggestions
devksingh4 3837365
Implement netID, emali, or UIN input for scanning
devksingh4 f27a946
Enable scanning for events by iCard swipe/netid entry
devksingh4 b767c7a
remove scan page unit tests until we can fix them later
devksingh4 8364b55
Route findUserByUin to performance-exempt lambda
devksingh4 62efaab
Allow permission to read user index
devksingh4 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,131 @@ | ||
| import { QueryCommand, type DynamoDBClient } from "@aws-sdk/client-dynamodb"; | ||
| import { unmarshall } from "@aws-sdk/util-dynamodb"; | ||
| import { TicketInfoEntry } from "api/routes/tickets.js"; | ||
| import { ValidLoggers } from "api/types.js"; | ||
| import { genericConfig } from "common/config.js"; | ||
| import { BaseError, DatabaseFetchError } from "common/errors/index.js"; | ||
|
|
||
| export type GetUserPurchasesInputs = { | ||
| dynamoClient: DynamoDBClient; | ||
| email: string; | ||
| logger: ValidLoggers; | ||
| }; | ||
|
|
||
| export type RawTicketEntry = { | ||
| ticket_id: string; | ||
| event_id: string; | ||
| payment_method: string; | ||
| purchase_time: string; | ||
| ticketholder_netid: string; // Note this is actually email... | ||
| used: boolean; | ||
| }; | ||
|
|
||
| export type RawMerchEntry = { | ||
| stripe_pi: string; | ||
| email: string; | ||
| fulfilled: boolean; | ||
| item_id: string; | ||
| quantity: number; | ||
| refunded: boolean; | ||
| scanIsoTimestamp?: string; | ||
| scannerEmail?: string; | ||
| size: string; | ||
| }; | ||
|
|
||
| export async function getUserTicketingPurchases({ | ||
| dynamoClient, | ||
| email, | ||
| logger, | ||
| }: GetUserPurchasesInputs) { | ||
| const issuedTickets: TicketInfoEntry[] = []; | ||
| const ticketCommand = new QueryCommand({ | ||
| TableName: genericConfig.TicketPurchasesTableName, | ||
| IndexName: "UserIndex", | ||
| KeyConditionExpression: "ticketholder_netid = :email", | ||
| ExpressionAttributeValues: { | ||
| ":email": { S: email }, | ||
| }, | ||
| }); | ||
| let ticketResults; | ||
| try { | ||
| ticketResults = await dynamoClient.send(ticketCommand); | ||
| if (!ticketResults || !ticketResults.Items) { | ||
| throw new Error("No tickets result"); | ||
| } | ||
| } catch (e) { | ||
| if (e instanceof BaseError) { | ||
| throw e; | ||
| } | ||
| logger.error(e); | ||
| throw new DatabaseFetchError({ | ||
| message: "Failed to get information from ticketing system.", | ||
| }); | ||
| } | ||
| const ticketsResultsUnmarshalled = ticketResults.Items.map( | ||
| (x) => unmarshall(x) as RawTicketEntry, | ||
| ); | ||
| for (const item of ticketsResultsUnmarshalled) { | ||
| issuedTickets.push({ | ||
| valid: !item.used, | ||
| type: "ticket", | ||
| ticketId: item.ticket_id, | ||
| purchaserData: { | ||
| email: item.ticketholder_netid, | ||
| productId: item.event_id, | ||
| quantity: 1, | ||
| }, | ||
| refunded: false, | ||
| fulfilled: item.used, | ||
| }); | ||
| } | ||
| return issuedTickets; | ||
| } | ||
|
|
||
| export async function getUserMerchPurchases({ | ||
| dynamoClient, | ||
| email, | ||
| logger, | ||
| }: GetUserPurchasesInputs) { | ||
| const issuedTickets: TicketInfoEntry[] = []; | ||
| const merchCommand = new QueryCommand({ | ||
| TableName: genericConfig.MerchStorePurchasesTableName, | ||
| IndexName: "UserIndex", | ||
| KeyConditionExpression: "email = :email", | ||
| ExpressionAttributeValues: { | ||
| ":email": { S: email }, | ||
| }, | ||
| }); | ||
| let ticketsResult; | ||
| try { | ||
| ticketsResult = await dynamoClient.send(merchCommand); | ||
| if (!ticketsResult || !ticketsResult.Items) { | ||
| throw new Error("No merch result"); | ||
| } | ||
| } catch (e) { | ||
| if (e instanceof BaseError) { | ||
| throw e; | ||
| } | ||
| logger.error(e); | ||
| throw new DatabaseFetchError({ | ||
| message: "Failed to get information from merch system.", | ||
| }); | ||
| } | ||
| const ticketsResultsUnmarshalled = ticketsResult.Items.map( | ||
| (x) => unmarshall(x) as RawMerchEntry, | ||
| ); | ||
| for (const item of ticketsResultsUnmarshalled) { | ||
| issuedTickets.push({ | ||
| valid: !item.refunded && !item.fulfilled, | ||
| type: "merch", | ||
| ticketId: item.stripe_pi, | ||
| purchaserData: { | ||
| email: item.email, | ||
| productId: item.item_id, | ||
| quantity: item.quantity, | ||
| }, | ||
| refunded: item.refunded, | ||
| fulfilled: item.fulfilled, | ||
| }); | ||
| } | ||
| return issuedTickets; | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ import membershipV2Plugin from "./routes/v2/membership.js"; | |
| import { docsHtml, securitySchemes } from "./docs.js"; | ||
| import syncIdentityPlugin from "./routes/syncIdentity.js"; | ||
| import { createRedisModule } from "./redis.js"; | ||
| import userRoute from "./routes/user.js"; | ||
| /** END ROUTES */ | ||
|
|
||
| export const instanceId = randomUUID(); | ||
|
|
@@ -373,6 +374,7 @@ Otherwise, email [[email protected]](mailto:[email protected]) for sup | |
| api.register(logsPlugin, { prefix: "/logs" }); | ||
| api.register(apiKeyRoute, { prefix: "/apiKey" }); | ||
| api.register(clearSessionRoute, { prefix: "/clearSession" }); | ||
| api.register(userRoute, { prefix: "/users" }); | ||
| if (app.runEnvironment === "dev") { | ||
| api.register(vendingPlugin, { prefix: "/vending" }); | ||
| } | ||
|
|
||
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.