Skip to content

Commit

Permalink
Tl bug fixes (#68)
Browse files Browse the repository at this point in the history
* fix existing day issue

* added year to return with ps

* removed both option

* removed redundant addition of C.year

---------

Co-authored-by: michellelin1 <[email protected]>
  • Loading branch information
ThatMegamind and michellelin1 authored Apr 29, 2024
1 parent 539084b commit 3b645a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions routes/day.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,25 @@ dayRouter.get('/:id', async (req, res) => {
dayRouter.post('/', async (req, res) => {
try {
const { eventDate, location, notes } = req.body;
const inUse = await db.query(`SELECT * FROM day WHERE event_date = $1;`, [eventDate]);
if (inUse.length) {
res.status(201).json({
status: 'Failed',
message: 'Day already exists',
});
const existingDay = await db.query(`SELECT * FROM day WHERE event_date = $1;`, [eventDate]);
if (existingDay.length) {
// day exists but has no events --> update location + notes return existing day_id
if (existingDay[0].day_count === 0) {
await db.query(`UPDATE day SET location = $1, notes = $2 WHERE id = $3;`, [
location,
notes,
existingDay[0].id,
]);
res.status(201).json({
status: 'Success',
id: existingDay[0].id,
});
} else {
res.status(201).json({
status: 'Failed',
message: 'Day already exists',
});
}
return;
}

Expand Down
2 changes: 1 addition & 1 deletion server/schema/catalog.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TYPE event AS ENUM ('guest speaker', 'study-trip', 'workshop', 'other');
CREATE TYPE subject AS ENUM ('life skills', 'science', 'technology', 'engineering', 'math', 'college readiness');
CREATE TYPE year AS ENUM ('junior', 'senior', 'both');
CREATE TYPE year AS ENUM ('junior', 'senior');
CREATE TYPE season AS ENUM ('spring', 'summer', 'fall');

DROP TABLE IF EXISTS catalog;
Expand Down

0 comments on commit 3b645a8

Please sign in to comment.