Skip to content

Commit

Permalink
merge in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
michellelin1 committed Mar 24, 2024
2 parents 7ba006b + b5327bf commit 08c7395
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const isInteger = (value) => {

// dependency for publishedSchedule.js
const calculateYear = (eventDate, gradeLevel) => {
if (gradeLevel) {
if (gradeLevel && gradeLevel.length) {
const currentDay = new Date(eventDate);
// console.log('current day', currentDay.getFullYear() + (currentDay.getMonth() >= 7 ? 2 : 1));
if (gradeLevel.toLowerCase() === 'junior') {
Expand Down
21 changes: 13 additions & 8 deletions routes/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ catalogRouter.get('/', async (req, res) => {

const offset = (page - 1) * limit;

let query = 'FROM catalog WHERE 1=1';
let query = 'FROM catalog WHERE 1=1 AND hidden = false';
// removed space at beginning here

const params = [];
Expand Down Expand Up @@ -77,7 +77,9 @@ catalogRouter.get('/', async (req, res) => {
catalogRouter.get('/:id', async (req, res) => {
try {
const { id } = req.params;
const allUsers = await db.query(`SELECT * FROM catalog WHERE id = $1;`, [id]);
const allUsers = await db.query(`SELECT * FROM catalog WHERE id = $1 AND hidden = false;`, [
id,
]);
res.status(200).json(keysToCamel(allUsers));
} catch (err) {
res.status(500).send(err.message);
Expand All @@ -87,7 +89,6 @@ catalogRouter.get('/:id', async (req, res) => {
// -- POST - Adds a new row to the catalog table
catalogRouter.post('/', async (req, res) => {
const { host, title, eventType, subject, description, year, season } = req.body;

try {
const returnedData = await db.query(
`INSERT INTO catalog (id, host, title, event_type, subject, description, year, season, hidden)
Expand All @@ -109,7 +110,7 @@ catalogRouter.post('/', async (req, res) => {
catalogRouter.put('/:id', async (req, res) => {
try {
const { id } = req.params;
const { host, title, eventType, subject, description, year, location, season } = req.body;
const { host, title, eventType, subject, description, year, season } = req.body;

const updatedCatalog = await db.query(
`UPDATE catalog SET
Expand All @@ -119,7 +120,6 @@ catalogRouter.put('/:id', async (req, res) => {
${subject ? 'subject = $(subject)::subject[], ' : ''}
${description ? 'description = $(description), ' : ''}
${year ? 'year = $(year)::year[], ' : ''}
${location ? 'location = $(location), ' : ''}
${season ? 'season = $(season)::season[], ' : ''}
id = '${id}'
WHERE id = '${id}'
Expand All @@ -132,7 +132,6 @@ catalogRouter.put('/:id', async (req, res) => {
description,
year,
id,
location,
season,
},
);
Expand All @@ -146,8 +145,14 @@ catalogRouter.put('/:id', async (req, res) => {
catalogRouter.delete('/:id', async (req, res) => {
try {
const { id } = req.params;
const delUser = await db.query(`DELETE FROM catalog WHERE id = $1 RETURNING *;`, [id]);
res.status(200).send(keysToCamel(delUser));
const inUse = await db.query(`SELECT * FROM published_schedule WHERE event_id = $1;`, [id]);
let hidden;
if (inUse && inUse.length) {
hidden = await db.query(`UPDATE catalog SET hidden = true WHERE id = $1 RETURNING *;`, [id]);
} else {
hidden = await db.query(`DELETE FROM catalog WHERE id = $1 RETURNING *;`, [id]);
}
res.status(200).send(keysToCamel(hidden));
} catch (err) {
res.status(500).send(err.message);
}
Expand Down
4 changes: 3 additions & 1 deletion routes/publishedSchedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ publishedScheduleRouter.get('/season', async (req, res) => {
(
SELECT
PS.id,
PS.event_id,
PS.day_id,
D.id AS day_day_id,
D.event_date,
Expand Down Expand Up @@ -197,6 +198,7 @@ publishedScheduleRouter.get('/season', async (req, res) => {
JSON_AGG(
json_build_object (
'id', seasonPS.id,
'event_id', seasonPS.event_id,
'title', seasonPS.title,
'event_type', seasonPS.event_type,
'year', seasonPS.year,
Expand Down Expand Up @@ -394,7 +396,7 @@ publishedScheduleRouter.put('/:id', async (req, res) => {
start_time = COALESCE($5, start_time),
end_time = COALESCE($6, end_time),
cohort = COALESCE($7, cohort),
notes = COALESCE($8, notes)
notes = COALESCE($8, notes),
created_on = COALESCE($9, created_on)
WHERE id = $10
Expand Down
15 changes: 14 additions & 1 deletion routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ userRouter.get('/', async (req, res) => {

userRouter.get('/pending-accounts', async (req, res) => {
try {
const pendingAccounts = await db.query(`SELECT * FROM users WHERE approved = FALSE;`);
const pendingAccounts = await db.query(
`SELECT * FROM users WHERE approved = FALSE ORDER BY first_name ASC;`,
);
res.status(200).json(keysToCamel(pendingAccounts));
} catch (err) {
res.status(500).send(err.message);
}
});

userRouter.get('/approved-accounts', async (req, res) => {
try {
const pendingAccounts = await db.query(
`SELECT * FROM users WHERE approved = TRUE ORDER BY first_name ASC;`,
);
res.status(200).json(keysToCamel(pendingAccounts));
} catch (err) {
res.status(500).send(err.message);
Expand Down
10 changes: 5 additions & 5 deletions server/schema/catalog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ CREATE TABLE catalog (
id SERIAL PRIMARY KEY,
host VARCHAR(50),
title VARCHAR(50) NOT NULL,
event_type event[] DEFAULT '{}',
subject subject[] DEFAULT '{}',
description VARCHAR(100),
year year[] DEFAULT '{}',
season season[] DEFAULT '{}',
event_type event[] NOT NULL DEFAULT '{}',
subject subject[] NOT NULL DEFAULT '{}',
description VARCHAR(256),
year year[] NOT NULL DEFAULT '{}',
season season[] NOT NULL DEFAULT '{}',
hidden BOOLEAN NOT NULL,
);
5 changes: 3 additions & 2 deletions server/schema/day.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
DROP TABLE IF EXISTS day;
CREATE TABLE IF NOT EXISTS day (
id serial PRIMARY KEY,
event_date DATE NOT NULL,
event_date DATE UNIQUE NOT NULL,
start_time TIME NOT NULL,
end_time TIME NOT NULL,
location VARCHAR( 256 ) NOT NULL,
notes VARCHAR( 250 )
notes VARCHAR( 250 ),
day_count INTEGER
);
2 changes: 1 addition & 1 deletion server/schema/published_schedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS published_schedule (
FOREIGN KEY (event_id)
REFERENCES catalog (id),
FOREIGN KEY (day_id)
REFERENCES day (id)
REFERENCES day (id) ON DELETE CASCADE
);

CREATE INDEX idx_day_id ON published_schedule (day_id);

0 comments on commit 08c7395

Please sign in to comment.