diff --git a/scripts/generateNFCsForEventRegistrations.js b/scripts/generateNFCsForEventRegistrations.js index 714c186..56dc6b1 100644 --- a/scripts/generateNFCsForEventRegistrations.js +++ b/scripts/generateNFCsForEventRegistrations.js @@ -95,7 +95,7 @@ const generateNFCsForEventRegistrations = async (eventID, year) => { registrationID: registration.id, profileID: profileID } - }, "biztechQRs" + (process.env.ENVIRONMENT || "")); + }, "biztechQRs"); // Get existing profile const existingProfile = await client.send(new GetCommand({ @@ -125,4 +125,25 @@ const generateNFCsForEventRegistrations = async (eventID, year) => { console.log(`created ${count} NFCs`); }; + +/* +This function is used to create backup NFCs in our DB so that we have extra QRs/NFCs day of. +*/ +const createExtraNFCs = async (eventID, year, count) => { + for (let i = 0; i < count; i++) { + const nfc = await create({ + id: humanId(), + "eventID;year": `${eventID};${year}`, + type: "NFC_ATTENDEE", + isUnlimitedScans: true, + data: { + registrationID: "DEFAULT", + profileID: "DEFAULT" + } + }, "biztechQRs"); + } +}; + + generateNFCsForEventRegistrations("blueprint", 2025); +// createExtraNFCs("blueprint", 2025, 15); diff --git a/scripts/generateQuestsForEventRegistrations.js b/scripts/generateQuestsForEventRegistrations.js index 00f2966..877c2ca 100644 --- a/scripts/generateQuestsForEventRegistrations.js +++ b/scripts/generateQuestsForEventRegistrations.js @@ -1,6 +1,12 @@ -import { PutCommand, QueryCommand } from "@aws-sdk/lib-dynamodb"; -import { QUESTS_TABLE, USER_REGISTRATIONS_TABLE } from "../constants/tables.js"; -import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; +import { + PutCommand, QueryCommand +} from "@aws-sdk/lib-dynamodb"; +import { + QUESTS_TABLE, USER_REGISTRATIONS_TABLE +} from "../constants/tables.js"; +import { + DynamoDBClient +} from "@aws-sdk/client-dynamodb"; const awsConfig = { accessKeyId: process.env.AWS_ACCESS_KEY_ID, @@ -40,19 +46,15 @@ const QUESTS = [ ]; const create = async (item, table) => { - try { - const params = { - Item: item, - TableName: table + (process.env.ENVIRONMENT || ""), - ConditionExpression: "attribute_not_exists(id)" - }; + const params = { + Item: item, + TableName: table + (process.env.ENVIRONMENT || ""), + ConditionExpression: "attribute_not_exists(id)" + }; - const command = new PutCommand(params); - const res = await docClient.send(command); - return res; - } catch (err) { - throw err; - } + const command = new PutCommand(params); + const res = await docClient.send(command); + return res; }; const userQuestsArray = (id, eventString) => { @@ -119,4 +121,4 @@ const questsForEventRegistrations = async (eventID, year) => { console.log(`Created ${count} Quest Entries for ${users} Users`); }; -await questsForEventRegistrations("blueprint", 2025); +questsForEventRegistrations("blueprint", 2025); diff --git a/services/profiles/handler.js b/services/profiles/handler.js index 24074c1..3c2e023 100644 --- a/services/profiles/handler.js +++ b/services/profiles/handler.js @@ -1,7 +1,11 @@ import db from "../../lib/db.js"; import helpers from "../../lib/handlerHelpers.js"; -import { isEmpty } from "../../lib/utils.js"; -import { humanId } from "human-id"; +import { + isEmpty +} from "../../lib/utils.js"; +import { + humanId +} from "human-id"; const PROFILES_TABLE = "biztechProfiles"; const REGISTRATIONS_TABLE = "biztechRegistrations"; @@ -10,15 +14,26 @@ const QRS_TABLE = "biztechQRs"; export const createProfile = async (event, ctx, callback) => { try { const data = JSON.parse(event.body); - + // Validate input helpers.checkPayloadProps(data, { - email: { required: true, type: "string" }, - eventID: { required: true, type: "string" }, - year: { required: true, type: "number" } + email: { + required: true, + type: "string" + }, + eventID: { + required: true, + type: "string" + }, + year: { + required: true, + type: "number" + } }); - const { email, eventID, year } = data; + const { + email, eventID, year + } = data; const eventIDAndYear = `${eventID};${year}`; // Check if profile already exists @@ -143,7 +158,9 @@ export const getProfile = async (event, ctx, callback) => { throw helpers.missingPathParamResponse("profileID"); } - const { profileID } = event.pathParameters; + const { + profileID + } = event.pathParameters; // Query using the GSI const result = await db.query( @@ -163,7 +180,7 @@ export const getProfile = async (event, ctx, callback) => { // Filter to only include public fields const publicProfile = filterPublicProfileFields(result[0]); - + const response = helpers.createResponse(200, publicProfile); callback(null, response); return response; @@ -180,7 +197,9 @@ export const getProfileByEmail = async (event, ctx, callback) => { throw helpers.missingPathParamResponse("email, eventID, or year"); } - const { email, eventID, year } = event.pathParameters; + const { + email, eventID, year + } = event.pathParameters; const eventIDAndYear = `${eventID};${year}`; // Get profile by email and eventID;year @@ -195,7 +214,7 @@ export const getProfileByEmail = async (event, ctx, callback) => { const response = helpers.createResponse(200, { profileID: profile.profileID }); - + callback(null, response); return response; } catch (err) { @@ -203,4 +222,4 @@ export const getProfileByEmail = async (event, ctx, callback) => { callback(null, err); return null; } -}; \ No newline at end of file +}; diff --git a/services/profiles/test/profileTests.js b/services/profiles/test/profileTests.js index b9a7140..6af19cb 100644 --- a/services/profiles/test/profileTests.js +++ b/services/profiles/test/profileTests.js @@ -2,8 +2,12 @@ const mochaPlugin = require("serverless-mocha-plugin"); const expect = mochaPlugin.chai.expect; -const { mockClient } = require("aws-sdk-client-mock"); -const { DynamoDBDocumentClient, GetCommand, PutCommand } = require("@aws-sdk/lib-dynamodb"); +const { + mockClient +} = require("aws-sdk-client-mock"); +const { + DynamoDBDocumentClient, GetCommand, PutCommand +} = require("@aws-sdk/lib-dynamodb"); const sinon = require("sinon"); const ddbMock = mockClient(DynamoDBDocumentClient); @@ -66,24 +70,37 @@ describe("Profiles Service", () => { ddbMock.on(GetCommand).callsFake((params) => { if (params.TableName.includes("biztechRegistrations")) { if (params.Key.id === testEmail && params.Key["eventID;year"] === `${testEventId};${testYear}`) { - return { Item: mockRegistration }; + return { + Item: mockRegistration + }; } - return { Item: undefined }; + return { + Item: undefined + }; } else if (params.TableName.includes("biztechProfiles")) { if (params.Key.email === testEmail && params.Key["eventID;year"] === `${testEventId};${testYear}`) { - return { Item: mockProfile }; + return { + Item: mockProfile + }; } - return { Item: undefined }; + return { + Item: undefined + }; } - return { Item: undefined }; + return { + Item: undefined + }; }); // Mock DynamoDB PutCommand ddbMock.on(PutCommand).callsFake((params) => { if (params.TableName.includes("biztechProfiles")) { - return { Item: params.Item }; + return { + Item: params.Item + }; } - return {}; + return { + }; }); // Stub db module functions @@ -91,7 +108,11 @@ describe("Profiles Service", () => { const params = { TableName: table, Key: { - ...(table.includes("biztechRegistrations") ? { id } : { email: id }), + ...(table.includes("biztechRegistrations") ? { + id + } : { + email: id + }), ...sortKey } }; @@ -243,4 +264,4 @@ describe("Profiles Service", () => { expect(body).to.deep.include(mockProfile); }); }); -}); \ No newline at end of file +});