diff --git a/constants/tables.js b/constants/tables.js index e9be69b1..4396dc2b 100644 --- a/constants/tables.js +++ b/constants/tables.js @@ -1,6 +1,7 @@ export const EVENTS_TABLE = "biztechEvents"; export const MEMBERSHIPS2021_TABLE = "biztechMemberships2021"; export const MEMBERS2022_TABLE = "biztechMembers2022"; +export const MEMBERS2023_TABLE = "biztechMembers2023"; export const MEMBERS2024_TABLE = "biztechMembers2024"; export const PRIZES_TABLE = "biztechPrizes"; export const STICKERS_TABLE = "biztechStickers"; diff --git a/services/members/handler.js b/services/members/handler.js index 35a32302..784df0b9 100644 --- a/services/members/handler.js +++ b/services/members/handler.js @@ -7,6 +7,15 @@ import docClient from "../../lib/docClient"; const { MEMBERS2024_TABLE } = require("../../constants/tables"); +const { + MEMBERS2023_TABLE +} = require("../../constants/tables"); +const { + MEMBERS2022_TABLE +} = require("../../constants/tables"); +const { + MEMBERSHIPS2021_TABLE +} = require("../../constants/tables"); export const create = async (event, ctx, callback) => { const timestamp = new Date().getTime(); @@ -39,7 +48,7 @@ export const create = async (event, ctx, callback) => { updatedAt: timestamp }, TableName: - MEMBERS2024_TABLE + + MEMBERS2024_TABLE + (process.env.ENVIRONMENT ? process.env.ENVIRONMENT : ""), ConditionExpression: "attribute_not_exists(id)" }; @@ -95,7 +104,35 @@ export const get = async (event, ctx, callback) => { export const getAll = async (event, ctx, callback) => { try { // scan the table - const members = await db.scan(MEMBERS2024_TABLE); + const year = event.queryStringParameters.year; + + // Get the table name based on the year from query param + let tableName; + switch (year) { + case "2021": + tableName = + MEMBERSHIPS2021_TABLE + + (process.env.ENVIRONMENT ? process.env.ENVIRONMENT : ""); + break; + case "2022": + tableName = + MEMBERS2022_TABLE + + (process.env.ENVIRONMENT ? process.env.ENVIRONMENT : ""); + break; + case "2023": + tableName = + MEMBERS2023_TABLE + + (process.env.ENVIRONMENT ? process.env.ENVIRONMENT : ""); + break; + case "2024": + tableName = + MEMBERS2024_TABLE + + (process.env.ENVIRONMENT ? process.env.ENVIRONMENT : ""); + break; + } + + const members = await db.scan(tableName); + // const members = await db.scan(MEMBERS2024_TABLE); // re-organize the response let response = {