More server stability

This commit is contained in:
2024-11-28 12:29:36 +01:00
parent 947ed225b6
commit 831a667a27
8 changed files with 56 additions and 29 deletions

View File

@@ -18,6 +18,9 @@ account.get("/", verifyToken, (req: Request, res: Response) => {
.then(accounts => { .then(accounts => {
res.status(200).json(accounts) res.status(200).json(accounts)
}) })
.catch(error => {
res.status(500).send()
})
}) })
// Login user // Login user
@@ -61,6 +64,9 @@ account.get("/account/data", verifyToken, async(req: Request, res: Response) =>
.then(account => { .then(account => {
res.status(200).json(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 => { .then(account => {
// Status: 201 Created // Status: 201 Created
res.status(201).json(account) res.status(201).json(account)
}).catch(reason => { }).catch(error => {
// Status: 409 Conflict // Status: 409 Conflict
res.status(409).json({ res.status(409).json({
code: 409, code: 409,
@@ -167,4 +173,7 @@ account.delete("/account/:id", (req: Request, res: Response) => {
.then(account => { .then(account => {
res.status(200).send() res.status(200).send()
}) })
.catch(error => {
res.status(500).send()
})
}) })

View File

@@ -65,6 +65,9 @@ band.get("/", (req: Request, res: Response) => {
res.status(200).json(bands) 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) res.status(200).json(band)
}) })
.catch(e => { .catch(error => {
res.status(404).send() res.status(404).send()
}) })
}) })
@@ -156,7 +159,7 @@ band.get("/search", async (req: Request, res: Response) => {
.then(bands => { .then(bands => {
res.status(200).json(bands) res.status(200).json(bands)
}) })
.catch(e => { .catch(error => {
res.status(200).send() res.status(200).send()
}) })
} }
@@ -175,6 +178,9 @@ band.patch("/", (req: Request, res: Response) => {
.then(result => { .then(result => {
res.status(200).json(result) res.status(200).json(result)
}) })
.catch(error => {
res.status(500).send()
})
}) })
@@ -186,6 +192,9 @@ band.post("/", (req: Request, res: Response) => {
.then(result => { .then(result => {
res.status(200).json(result) res.status(200).json(result)
}) })
.catch(error => {
res.status(500).send()
})
}) })
/** /**

View File

@@ -8,4 +8,7 @@ city.get("/", (req: Request, res: Response) => {
.then(cities => { .then(cities => {
res.status(200).json(cities) res.status(200).json(cities)
}) })
.catch(error => {
res.status(500).send()
})
}) })

View File

@@ -35,6 +35,9 @@ concert.get("/", (req: Request, res: Response) => {
res.status(200).json(concerts) res.status(200).json(concerts)
}) })
.catch(error => {
res.status(500).send()
})
}) })
@@ -154,4 +157,7 @@ concert.get("/search", (req: Request, res: Response) => {
.then(concerts => { .then(concerts => {
res.status(200).json(concerts) res.status(200).json(concerts)
}) })
.catch(error => {
res.status(500).send()
})
}) })

View File

@@ -11,13 +11,17 @@ export const exercises = Router()
exercises.get("/", (req: Request, res: Response) => { exercises.get("/", (req: Request, res: Response) => {
Exercise.findAll({ Exercise.findAll({
include: [ ExerciseGroup ] 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 changed: changed
}) })
}) })
.catch(error => {
res.status(500).send()
// 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()
// })
// })
}) })

View File

@@ -58,7 +58,5 @@ files.get("/:folder", async (req: Request, res: Response) => {
* Upload a file * Upload a file
*/ */
files.post("/", upload.single("file"), function (req: Request, res: Response, next: NextFunction) { files.post("/", upload.single("file"), function (req: Request, res: Response, next: NextFunction) {
console.log(req.file)
res.status(200).send() res.status(200).send()
}) })

View File

@@ -98,7 +98,7 @@ location.get("/location/:urlName", (req: Request, res: Response) => {
res.status(200).json(location) res.status(200).json(location)
}) })
.catch(e => { .catch(error => {
res.status(404).send() res.status(404).send()
}) })
}) })
@@ -133,4 +133,7 @@ location.get("/search", (req: Request, res: Response) => {
.then(locations => { .then(locations => {
res.status(200).json(locations) res.status(200).json(locations)
}) })
.catch(error => {
res.status(500).send()
})
}) })

View File

@@ -43,6 +43,9 @@ order.get("/", (req: Request, res: Response) => {
.then(orders => { .then(orders => {
res.status(200).json(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 => { .then(orders => {
res.status(200).json(orders) res.status(200).json(orders)
}) })
.catch(error => {
res.status(500).send()
})
}) })
// Place a new order // Place a new order
@@ -116,4 +122,7 @@ order.post("/", (req: Request, res: Response) => {
// Created // Created
res.status(201).json(order) res.status(201).json(order)
}) })
.catch(error => {
res.status(500).send()
})
}) })