mirror of
https://github.com/Floriansylvain/CineAllo.git
synced 2026-08-19 19:53:16 +02:00
🎨 - Improved prisma funcs usage
This commit is contained in:
+7
-7
@@ -14,26 +14,26 @@ showsRouter.get('/', async function(req, res, next) {
|
|||||||
showsRouter.get('/:id', function (req, res, next) {
|
showsRouter.get('/:id', function (req, res, next) {
|
||||||
prisma.serie.findUniqueOrThrow({
|
prisma.serie.findUniqueOrThrow({
|
||||||
where: {
|
where: {
|
||||||
title: {
|
title: req.params.id
|
||||||
equals: req.params.id
|
|
||||||
}
|
}
|
||||||
}})
|
})
|
||||||
.then(show => res.send(show))
|
.then(show => res.send({ show }))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error instanceof Prisma.NotFoundError) {
|
if (error instanceof Prisma.NotFoundError) {
|
||||||
next(createHttpError(404, 'Show unknown.'))
|
next(createHttpError(404, 'Show not found.'))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
showsRouter.post('/', async function (req, res, next) {
|
showsRouter.post('/', function (req, res, next) {
|
||||||
prisma.serie.create({
|
prisma.serie.create({
|
||||||
data: {
|
data: {
|
||||||
title: req.body.title,
|
title: req.body.title,
|
||||||
date: req.body.date,
|
date: req.body.date,
|
||||||
description: req.body.description,
|
description: req.body.description,
|
||||||
thumbmailURL: req.body.thumbmailURL
|
thumbmailURL: req.body.thumbmailURL
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
.then(() => res.send({ message: 'Show posted!' }))
|
.then(() => res.send({ message: 'Show posted!' }))
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
next(createHttpError(400, 'Check your show model/content.'))
|
next(createHttpError(400, 'Check your show model/content.'))
|
||||||
|
|||||||
Reference in New Issue
Block a user