From feca0934a37b9f55084941be5d68452f7126df1c Mon Sep 17 00:00:00 2001 From: TobiZog Date: Thu, 28 Nov 2024 12:29:36 +0100 Subject: [PATCH] More server stability --- backend/routes/account.routes.ts | 11 +++++++++- backend/routes/band.routes.ts | 13 +++++++++-- backend/routes/city.routes.ts | 3 +++ backend/routes/concert.routes.ts | 6 ++++++ backend/routes/exercise.routes.ts | 36 +++++++++++-------------------- backend/routes/files.routes.ts | 2 -- backend/routes/location.routes.ts | 5 ++++- backend/routes/order.routes.ts | 9 ++++++++ 8 files changed, 56 insertions(+), 29 deletions(-) diff --git a/backend/routes/account.routes.ts b/backend/routes/account.routes.ts index d95a65a..0e6d4ca 100644 --- a/backend/routes/account.routes.ts +++ b/backend/routes/account.routes.ts @@ -18,6 +18,9 @@ account.get("/", verifyToken, (req: Request, res: Response) => { .then(accounts => { res.status(200).json(accounts) }) + .catch(error => { + res.status(500).send() + }) }) // Login user @@ -61,6 +64,9 @@ account.get("/account/data", verifyToken, async(req: Request, res: Response) => .then(account => { res.status(200).json(account) }) + .catch(error => { + res.status(500).send() + }) }) @@ -102,7 +108,7 @@ account.post("/account", async (req: Request, res: Response) => { .then(account => { // Status: 201 Created res.status(201).json(account) - }).catch(reason => { + }).catch(error => { // Status: 409 Conflict res.status(409).json({ code: 409, @@ -167,4 +173,7 @@ account.delete("/account/:id", (req: Request, res: Response) => { .then(account => { res.status(200).send() }) + .catch(error => { + res.status(500).send() + }) }) \ No newline at end of file diff --git a/backend/routes/band.routes.ts b/backend/routes/band.routes.ts index 447d6fb..af28513 100644 --- a/backend/routes/band.routes.ts +++ b/backend/routes/band.routes.ts @@ -65,6 +65,9 @@ band.get("/", (req: Request, res: Response) => { res.status(200).json(bands) }) + .catch(error => { + res.status(500).send() + }) }) /** @@ -122,7 +125,7 @@ band.get("/band/:name", (req: Request, res: Response) => { res.status(200).json(band) }) - .catch(e => { + .catch(error => { res.status(404).send() }) }) @@ -156,7 +159,7 @@ band.get("/search", async (req: Request, res: Response) => { .then(bands => { res.status(200).json(bands) }) - .catch(e => { + .catch(error => { res.status(200).send() }) } @@ -175,6 +178,9 @@ band.patch("/", (req: Request, res: Response) => { .then(result => { res.status(200).json(result) }) + .catch(error => { + res.status(500).send() + }) }) @@ -186,6 +192,9 @@ band.post("/", (req: Request, res: Response) => { .then(result => { res.status(200).json(result) }) + .catch(error => { + res.status(500).send() + }) }) /** diff --git a/backend/routes/city.routes.ts b/backend/routes/city.routes.ts index ed8e52c..6680eae 100644 --- a/backend/routes/city.routes.ts +++ b/backend/routes/city.routes.ts @@ -8,4 +8,7 @@ city.get("/", (req: Request, res: Response) => { .then(cities => { res.status(200).json(cities) }) + .catch(error => { + res.status(500).send() + }) }) \ No newline at end of file diff --git a/backend/routes/concert.routes.ts b/backend/routes/concert.routes.ts index c0a6654..d0dcbd4 100644 --- a/backend/routes/concert.routes.ts +++ b/backend/routes/concert.routes.ts @@ -35,6 +35,9 @@ concert.get("/", (req: Request, res: Response) => { res.status(200).json(concerts) }) + .catch(error => { + res.status(500).send() + }) }) @@ -154,4 +157,7 @@ concert.get("/search", (req: Request, res: Response) => { .then(concerts => { res.status(200).json(concerts) }) + .catch(error => { + res.status(500).send() + }) }) \ No newline at end of file diff --git a/backend/routes/exercise.routes.ts b/backend/routes/exercise.routes.ts index 855c3f9..162e49f 100644 --- a/backend/routes/exercise.routes.ts +++ b/backend/routes/exercise.routes.ts @@ -11,13 +11,17 @@ export const exercises = Router() exercises.get("/", (req: Request, res: Response) => { Exercise.findAll({ include: [ ExerciseGroup ] - }).then(result => { - result.sort((a, b) => { - return (a.dataValues.exerciseGroup.dataValues.groupNr * 10 + a.dataValues.exerciseNr) > (b.dataValues.exerciseGroup.dataValues.groupNr * 10 + b.dataValues.exerciseNr) ? 1 : -1 - }) - - res.status(200).json(result) }) + .then(result => { + result.sort((a, b) => { + return (a.dataValues.exerciseGroup.dataValues.groupNr * 10 + a.dataValues.exerciseNr) > (b.dataValues.exerciseGroup.dataValues.groupNr * 10 + b.dataValues.exerciseNr) ? 1 : -1 + }) + + res.status(200).json(result) + }) + .catch(error => { + res.status(500).send() + }) }) /** @@ -54,21 +58,7 @@ exercises.post("/:groupNr/:exerciseNr/:state", (req: Request, res: Response) => changed: changed }) }) - - - // ExerciseGroup.findOne({ - // where: { groupNr: req.params.groupNr } - // }) - // .then(group => { - // Exercise.findOne({ - // where: { - // exerciseNr: req.params.exerciseNr, - // exerciseGroupId: group.id - // } - // }) - // .then(exercise => { - // exercise.update({ solved: req.params.state == "1"}) - // res.status(200).send() - // }) - // }) + .catch(error => { + res.status(500).send() + }) }) \ No newline at end of file diff --git a/backend/routes/files.routes.ts b/backend/routes/files.routes.ts index 19c9400..8651b6a 100644 --- a/backend/routes/files.routes.ts +++ b/backend/routes/files.routes.ts @@ -58,7 +58,5 @@ files.get("/:folder", async (req: Request, res: Response) => { * Upload a file */ files.post("/", upload.single("file"), function (req: Request, res: Response, next: NextFunction) { - console.log(req.file) - res.status(200).send() }) \ No newline at end of file diff --git a/backend/routes/location.routes.ts b/backend/routes/location.routes.ts index c6d63e5..b3f345e 100644 --- a/backend/routes/location.routes.ts +++ b/backend/routes/location.routes.ts @@ -98,7 +98,7 @@ location.get("/location/:urlName", (req: Request, res: Response) => { res.status(200).json(location) }) - .catch(e => { + .catch(error => { res.status(404).send() }) }) @@ -133,4 +133,7 @@ location.get("/search", (req: Request, res: Response) => { .then(locations => { res.status(200).json(locations) }) + .catch(error => { + res.status(500).send() + }) }) \ No newline at end of file diff --git a/backend/routes/order.routes.ts b/backend/routes/order.routes.ts index d9528dd..21d890c 100644 --- a/backend/routes/order.routes.ts +++ b/backend/routes/order.routes.ts @@ -43,6 +43,9 @@ order.get("/", (req: Request, res: Response) => { .then(orders => { res.status(200).json(orders) }) + .catch(error => { + res.status(500).send() + }) }) @@ -90,6 +93,9 @@ order.get("/:id", (req: Request, res: Response) => { .then(orders => { res.status(200).json(orders) }) + .catch(error => { + res.status(500).send() + }) }) // Place a new order @@ -116,4 +122,7 @@ order.post("/", (req: Request, res: Response) => { // Created res.status(201).json(order) }) + .catch(error => { + res.status(500).send() + }) }) \ No newline at end of file