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

Tl bug fixes #68

Merged
merged 6 commits into from
Apr 29, 2024
Merged
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
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
Loading