- added some (non-working) category edit

This commit is contained in:
2023-05-10 21:28:11 +02:00
parent 7cfca9abac
commit c6fb84759f
4 changed files with 75 additions and 4 deletions

View File

@ -1,5 +1,5 @@
import express, { Request, Response } from 'express';
import { prisma, __path } from '../../index.js';
import { prisma, __path, log } from '../../index.js';
export default (req: Request, res: Response) => {
// If method is get, render the page
@ -22,6 +22,9 @@ export default (req: Request, res: Response) => {
res.status(400).render(__path + '/src/frontend/errors/400.eta.html');
return;
}
if(!req.body.editCategoryModalIsEdit) {
console.log('is not edit');
// Save data to category table
prisma.category.create({
data: {
@ -34,9 +37,29 @@ export default (req: Request, res: Response) => {
})
.catch((err) => {
// TODO Catch if is a duplicate error and show a message to the user
// TODO Fix this as it throws an error on the error page
log.db.error(err);
res.status(500).render(__path + '/src/frontend/errors/dbError.eta.html', { error: err });
});
} else {
// Save data to category table
prisma.category.update({
where: {
id: parseInt(req.body.editCategoryModalId)
},
data: {
name: req.body.name,
description: req.body.description,
},
})
.then(() => {
res.redirect('/allCategories');
})
.catch((err) => {
// TODO Catch if is a duplicate error and show a message to the user
log.db.error(err);
res.status(500).render(__path + '/src/frontend/errors/dbError.eta.html', { error: err });
});
}
}
};