Skip to content

add exchanging of merch #105

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

Draft
wants to merge 75 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
1af8f08
exchange route
jlevine18 Apr 2, 2025
3ddc3a9
Merge branch 'main' into merch-exchanges
jlevine18 Apr 2, 2025
59ca93f
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 15, 2025
0d78a31
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 15, 2025
52e763e
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 19, 2025
98797f4
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 20, 2025
759dde2
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 20, 2025
c83d796
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 22, 2025
b5d2e42
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 22, 2025
bef04d9
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 22, 2025
cf2a058
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 23, 2025
69daa44
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 23, 2025
553b932
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 23, 2025
97d7b0b
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 23, 2025
1039826
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 23, 2025
831f5f2
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 24, 2025
8d299b2
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 24, 2025
770b179
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 25, 2025
6554b57
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 27, 2025
8d379f1
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 29, 2025
2623ad7
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 29, 2025
55685ed
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 29, 2025
cffba66
Auto-update feature branch with changes from the main branch
github-actions[bot] Jun 29, 2025
359762c
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 3, 2025
10c41e7
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 3, 2025
8200e65
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 3, 2025
0e8f298
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 3, 2025
852f31a
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 5, 2025
684813d
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 5, 2025
d28c016
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 5, 2025
93cea2d
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 5, 2025
51dd886
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 5, 2025
d15d502
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 5, 2025
bc13719
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 5, 2025
aa46dca
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 5, 2025
ae5b653
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
958fc78
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
44e20b3
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
c9e4ed9
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
a0d7f43
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
7506723
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
609060f
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
d7127d4
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
79ff5cf
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
8a085df
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
84b1912
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
624da76
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
2c4e550
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 6, 2025
31e82f4
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 7, 2025
b7e59b4
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 7, 2025
a0ab0ad
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 7, 2025
98b3e99
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 7, 2025
e7ec6e2
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 7, 2025
11f30eb
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 8, 2025
0215234
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 9, 2025
bf6fe1c
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 9, 2025
1f2f63e
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 11, 2025
8b018a3
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 11, 2025
3b3ae20
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 11, 2025
aab65cd
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 11, 2025
5624b45
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 12, 2025
7ddf619
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 12, 2025
65e899d
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 12, 2025
9522cde
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 12, 2025
8578e8c
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 12, 2025
1a2e823
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 12, 2025
56bf181
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 12, 2025
70ee524
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 12, 2025
a6d251b
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 13, 2025
e3b8516
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 13, 2025
e35a0eb
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 13, 2025
293a389
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 13, 2025
4c0cf4a
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 13, 2025
28369f0
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 14, 2025
1338185
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions src/api/routes/tickets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
QueryCommand,
ScanCommand,
UpdateItemCommand,
TransactWriteItemsCommand,
TransactWriteItemsInput,
} from "@aws-sdk/client-dynamodb";
import { genericConfig } from "../../common/config.js";
import {
Expand Down Expand Up @@ -94,6 +96,21 @@ const postSchema = z.union([postMerchSchema, postTicketSchema]);

type VerifyPostRequest = z.infer<typeof postSchema>;

const itemExchangeSchema = z.object({
itemId: z.string().min(1),
ticketId: z.string().min(1),
originalSize: z.string(),
newSize: z.string(),
quantityExchanged: z.number(),
});

type ItemExchangeRequest = z.infer<typeof itemExchangeSchema>;

const itemExchangeResponseSchema = z.object({
ticketId: z.string().min(1),
successful: z.boolean(),
});

type TicketsGetRequest = {
Params: { id: string };
Querystring: { type: string };
Expand Down Expand Up @@ -477,6 +494,65 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
});
},
);
fastify.post<{ Body: ItemExchangeRequest }>(
"/exchange",
{
schema: {
response: { 200: itemExchangeResponseSchema },
},
preValidation: async (request, reply) => {
await fastify.zodValidateBody(request, reply, itemExchangeSchema);
},
onRequest: async (request, reply) => {
await fastify.authorize(request, reply, [AppRoles.TICKETS_SCANNER]);
},
},
async (request, reply) => {
const transaction: TransactWriteItemsInput = {
TransactItems: [
{
Update: {
Key: { itemId: { S: request.body.itemId } },
UpdateExpression:
"SET total_avail.#sizeold = total_avail.#sizeold + :quantity, total_avail.#sizenew = total_avail.#sizenew + :quantity",
ConditionExpression: "total_avail.#sizenew >= :quantity",
ExpressionAttributeNames: {
"#sizeold": request.body.originalSize,
"#sizenew": request.body.newSize,
},
ExpressionAttributeValues: {
":quantity": { N: request.body.quantityExchanged.toString() },
},
TableName: genericConfig.MerchStoreMetadataTableName,
},
},
{
Update: {
Key: { stripePi: { S: request.body.ticketId } },
UpdateExpression: "SET size = :sizenew",
ConditionExpression: "quantity >= :quantity",
ExpressionAttributeValues: {
":quantity": { N: request.body.quantityExchanged.toString() },
":sizenew": { S: request.body.newSize },
},
TableName: genericConfig.MerchStorePurchasesTableName,
},
},
],
};
const command = new TransactWriteItemsCommand(transaction);
try {
const resp = await fastify.dynamoClient.send(command);
if (resp.$metadata.httpStatusCode == 200) {
reply.send({ ticketId: request.body.ticketId, successful: true });
} else {
reply.send({ ticketId: request.body.ticketId, successful: false });
}
} catch {
reply.send({ ticketId: request.body.ticketId, successful: false });
}
},
);
};

export default ticketsPlugin;