generated from ctc-uci/npo-template-merged
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created events and bookings endpoints bc we are goated
Co-authored-by: Aston Chan <[email protected]>
- Loading branch information
1 parent
293e922
commit 4df361a
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import express from "express"; | ||
|
||
import { db } from "../db/db-pgp"; | ||
import { keysToCamel } from "../common/utils"; | ||
|
||
export const bookingsRouter = express.Router(); | ||
bookingsRouter.use(express.json()); | ||
|
||
bookingsRouter.get("/:id", async (req, res) => { | ||
try { | ||
const { id } = req.params; | ||
const data = await db.query(`SELECT * FROM bookings WHERE id = $1`, [ | ||
id | ||
]); | ||
res.status(200).json(keysToCamel(data)); | ||
} catch (err) { | ||
res.status(500).send(err.message); | ||
} | ||
}); | ||
|
||
bookingsRouter.get("/event/:id", async (req, res) => { | ||
try { | ||
const { id } = req.params; | ||
const { start, end } = req.query; | ||
|
||
let data; | ||
if (start && end) | ||
{ | ||
data = await db.query(`SELECT * FROM bookings WHERE event_id = $1 AND start_time = $2 AND end_time = $3`, [ | ||
id, | ||
start, | ||
end | ||
]); | ||
} | ||
else if (!(start && end)) | ||
{ | ||
data = await db.query(`SELECT * FROM bookings WHERE event_id = $1`, [ | ||
id | ||
]); | ||
} | ||
res.status(200).json(keysToCamel(data)); | ||
} catch (err) { | ||
res.status(500).send(err.message); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import express from "express"; | ||
import { db } from "../db/db-pgp"; | ||
import { keysToCamel } from "../common/utils"; | ||
|
||
export const eventsRouter = express.Router(); | ||
eventsRouter.use(express.json()); | ||
|
||
eventsRouter.get("/", async (req, res) => { | ||
try { | ||
const data = await db.query(`SELECT * FROM events`); | ||
res.status(200).json(keysToCamel(data)); | ||
} catch (err) { | ||
res.status(500).send(err.message); | ||
} | ||
}); | ||
|
||
eventsRouter.delete("/:id", async (req, res) => { | ||
try { | ||
const { id } = req.params; | ||
const data = await db.query(`DELETE FROM events WHERE id = $1`, [id]); | ||
res.status(200).json(keysToCamel(data)); | ||
} catch (err) { | ||
res.status(500).send(err.message); | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters