Migrated route / Fixed import
- Migrate categoryManager to new route schema. - Fiex csv Import description.
This commit is contained in:
parent
b1a73ebd4a
commit
38cd29943f
@ -1,9 +1,7 @@
|
||||
import express, { Request, Response } from 'express';
|
||||
import { prisma, __path, log } from '../../../index.js';
|
||||
|
||||
export default (req: Request, res: Response) => {
|
||||
// If method is get, render the page
|
||||
if (req.method === 'GET') {
|
||||
function get(req: Request, res: Response) {
|
||||
// Render the page
|
||||
prisma.itemCategory
|
||||
.findMany({})
|
||||
@ -15,22 +13,25 @@ export default (req: Request, res: Response) => {
|
||||
console.error(err);
|
||||
res.status(500).render(__path + '/src/frontend/errors/dbError.eta.html', { error: err });
|
||||
});
|
||||
} else {
|
||||
}
|
||||
|
||||
function post(req: Request, res: Response) {
|
||||
console.log(req.body);
|
||||
// Check if required fields are filled in
|
||||
if (!req.body.name || !req.body.description) {
|
||||
if (!req.body.name) {
|
||||
res.status(400).render(__path + '/src/frontend/errors/400.eta.html');
|
||||
return;
|
||||
}
|
||||
|
||||
if(!req.body.editCategoryModalIsEdit) {
|
||||
if (!req.body.editCategoryModalIsEdit) {
|
||||
console.log('is not edit');
|
||||
// Save data to category table
|
||||
prisma.itemCategory.create({
|
||||
prisma.itemCategory
|
||||
.create({
|
||||
data: {
|
||||
name: req.body.name,
|
||||
description: req.body.description,
|
||||
},
|
||||
description: req.body.description
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
res.redirect('categories');
|
||||
@ -42,14 +43,15 @@ export default (req: Request, res: Response) => {
|
||||
});
|
||||
} else {
|
||||
// Save data to category table
|
||||
prisma.itemCategory.update({
|
||||
prisma.itemCategory
|
||||
.update({
|
||||
where: {
|
||||
id: parseInt(req.body.editCategoryModalId)
|
||||
},
|
||||
data: {
|
||||
name: req.body.name,
|
||||
description: req.body.description,
|
||||
},
|
||||
description: req.body.description
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
res.redirect('categories');
|
||||
@ -60,6 +62,6 @@ export default (req: Request, res: Response) => {
|
||||
res.status(500).render(__path + '/src/frontend/errors/dbError.eta.html', { error: err });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
export default { get, post };
|
||||
|
@ -42,7 +42,8 @@ function post(req: Request, res: Response) {
|
||||
categories.forEach((category: string) => {
|
||||
const promise = prisma.itemCategory.create({
|
||||
data: {
|
||||
name: category
|
||||
name: category,
|
||||
description: ''
|
||||
}
|
||||
});
|
||||
categoryPromises.push(promise);
|
||||
@ -61,7 +62,7 @@ function post(req: Request, res: Response) {
|
||||
comment: record.comment,
|
||||
category: {
|
||||
connect: {
|
||||
name: record.category
|
||||
name: record.category,
|
||||
}
|
||||
},
|
||||
SKU: record.sku,
|
||||
|
@ -11,8 +11,7 @@ import startpageRoute from './startpage.js';
|
||||
const Router = express.Router({ strict: false });
|
||||
|
||||
Router.route('/test').get(testRoute.get);
|
||||
|
||||
Router.use('/categories', categoryManager); // TODO: Needs refactoring to new route format.
|
||||
Router.route('/categories').get(categoryManager.get).post(categoryManager.post);
|
||||
Router.route('/storages').get(storageManager.get);
|
||||
Router.route('/import/csv').get(csvImportRoute.get).post(csvImportRoute.post);
|
||||
Router.route('/').get(startpageRoute.get);
|
||||
|
Loading…
Reference in New Issue
Block a user