Skip to content
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

See previous years' member stats #296

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions constants/tables.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
41 changes: 39 additions & 2 deletions services/members/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)"
};
Expand Down Expand Up @@ -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 = {
Expand Down