Skip to content

Commit

Permalink
updated to use numeric syntax for sql queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Jian committed Dec 8, 2023
1 parent dd697a0 commit 817e2fe
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions routes/publishedSchedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ publishedScheduleRouter.post('/', async (req, res) => {
});

// PUT/:id - Updates an existing row given an id
publishedScheduleRouter.put('/id', async (req, res) => {
publishedScheduleRouter.put('/:id', async (req, res) => {

try {
const { id } = req.params;
const {
event_id: eventId,
confirmed,
confirmed_on: confirmedOn,
start_time: startTime,
end_time: endTime,
Expand All @@ -113,16 +114,16 @@ publishedScheduleRouter.put('/id', async (req, res) => {
`
UPDATE published_schedule
SET
event_id = COALESCE(?, event_id),
confirmed = COALESCE(?, confirmed),
confirmed_on = COALESCE(?, confirmed_on),
start_time = COALESCE(?, start_time),
end_time = COALESCE(?, end_time),
cohort = COALESCE(?, cohort),
notes = COALESCE(?, notes)
WHERE id = ?;
event_id = COALESCE($1, event_id),
confirmed = COALESCE($2, confirmed),
confirmed_on = COALESCE($3, confirmed_on),
start_time = COALESCE($4, start_time),
end_time = COALESCE($5, end_time),
cohort = COALESCE($6, cohort),
notes = COALESCE($7, notes)
WHERE id = $8;
`,
[id, eventId, confirmedOn, startTime, endTime, cohort, notes],
[eventId, confirmed, confirmedOn, startTime, endTime, cohort, notes, id],
);
res.status(204).json(keysToCamel(updatedPublishedSchedule));
} catch (err) {
Expand All @@ -137,7 +138,7 @@ publishedScheduleRouter.put('/id', async (req, res) => {
await db.query(
`
DELETE FROM published_schedule
WHERE id = ?;
WHERE id = $1;
`,
[id]
);
Expand Down

0 comments on commit 817e2fe

Please sign in to comment.