Skip to content

Commit

Permalink
Merge branch 'dev' into 41-catalog-match-high-fidelity--additional-fi…
Browse files Browse the repository at this point in the history
…lter-functionality
  • Loading branch information
ThatMegamind authored Mar 5, 2024
2 parents 3f07990 + 475e3d9 commit e9cd097
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
24 changes: 23 additions & 1 deletion common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,26 @@ const keysToCamel = (data) => {
return data;
};

module.exports = { keysToCamel, isInteger, calculateYear };
const getSeasonFromMonthAndYear = (month, year) => {
if (month === 11) {
return `Winter ${year + 1}`;
}
if (month === 0 || month === 1) {
return `Winter ${year}`;
}
// spring
// march-may -> winter [year]
if (month >= 2 && month <= 4) {
return `Winter ${year}`;
}
// summer
// june-august -> summer [year]
if (month >= 5 && month <= 7) {
return `Summer ${year}`;
}
// fall
// september-november -> fall [year]
return `Fall ${year}`;
};

module.exports = { keysToCamel, isInteger, calculateYear, getSeasonFromMonthAndYear };
42 changes: 14 additions & 28 deletions routes/publishedSchedule.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express');
const { db } = require('../server/db');
const { keysToCamel, calculateYear } = require('../common/utils');
const { keysToCamel, calculateYear, getSeasonFromMonthAndYear } = require('../common/utils');

const publishedScheduleRouter = express.Router();

Expand Down Expand Up @@ -96,30 +96,7 @@ publishedScheduleRouter.get('/all-seasons', async (req, res) => {
const formattedDate = new Date(date.event_date);
const year = formattedDate.getFullYear();
const month = formattedDate.getMonth();
// const day = formattedDate.getDate();

// winter
// december (11) -> winter [year + 1]
// january (0) - february (1) -> winter [year]
if (month === 11) {
return `Winter ${year + 1}`;
}
if (month === 0 || month === 1) {
return `Winter ${year}`;
}
// spring
// march-may -> winter [year]
if (month >= 2 && month <= 4) {
return `Winter ${year}`;
}
// summer
// june-august -> summer [year]
if (month >= 5 && month <= 7) {
return `Summer ${year}`;
}
// fall
// september-november -> fall [year]
return `Fall ${year}`;
return getSeasonFromMonthAndYear(month, year);
};

try {
Expand All @@ -130,12 +107,20 @@ publishedScheduleRouter.get('/all-seasons', async (req, res) => {
published_schedule AS PS, day AS D
WHERE
D.id = PS.day_id
ORDER BY
D.event_date DESC;
`,
);
const allSeasonsResult = allDatesResult.map((row) => {
return getSeason(row);
const allUniqueSeasonsResult = [];

// Get all unique seasons by order of season, from most recent to least
allDatesResult.forEach((row) => {
const season = getSeason(row);
if (!allUniqueSeasonsResult.includes(season)) {
allUniqueSeasonsResult.push(season);
}
});
const allUniqueSeasonsResult = [...new Set(allSeasonsResult)];

res.status(200).json(keysToCamel(allUniqueSeasonsResult));
} catch (err) {
res.status(500).send(err.message);
Expand Down Expand Up @@ -198,6 +183,7 @@ publishedScheduleRouter.get('/season', async (req, res) => {
WHERE
D.event_date >= $1::date AND D.event_date <= $2::date
AND D.id = PS.day_id
ORDER BY PS.start_time ASC
)
SELECT event_date,
json_build_object (
Expand Down
6 changes: 3 additions & 3 deletions routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ userRouter.get('/:uid', async (req, res) => {

userRouter.post('/create', async (req, res) => {
try {
const { id, email, type, approved, approvedOn } = req.body;
const { id, email, type, approved, approvedOn, firstName, lastName } = req.body;
await db.query(
`INSERT INTO users (id, email, "type", approved, approved_on) VALUES ($1, $2, $3, $4, $5);`,
[id, email, type, approved, approvedOn],
`INSERT INTO users (id, email, "type", approved, approved_on, first_name, last_name) VALUES ($1, $2, $3, $4, $5, $6, $7);`,
[id, email, type, approved, approvedOn, firstName, lastName],
);
res.status(201).json({
id,
Expand Down
4 changes: 3 additions & 1 deletion server/schema/users.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TYPE account_type as ENUM ('superadmin', 'admin');
CREATE TYPE account_type as ENUM ('admin', 'student');

DROP TABLE IF EXISTS users;

Expand All @@ -8,4 +8,6 @@ CREATE TABLE users (
type account_type NOT NULL,
approved BOOLEAN NOT NULL,
approved_on DATE NOT NULL,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL
);

0 comments on commit e9cd097

Please sign in to comment.