111 lines
2.8 KiB
JavaScript
111 lines
2.8 KiB
JavaScript
const express = require('express');
|
|
const { verifyToken } = require('../auth');
|
|
const {
|
|
createCategory,
|
|
createConsumptionReference,
|
|
createProduct,
|
|
deleteCategory,
|
|
deleteConsumptionReference,
|
|
deleteProduct,
|
|
getCatalogSummary,
|
|
listCategories,
|
|
listConsumptionReferences,
|
|
listProducts
|
|
} = require('../services/catalogService');
|
|
const { importTinyProductCompositionExport } = require('../services/productionOrderService');
|
|
|
|
const router = express.Router();
|
|
|
|
router.get('/catalog', verifyToken, async (req, res, next) => {
|
|
try {
|
|
res.json(await getCatalogSummary());
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
router.get('/catalog/categories', verifyToken, async (req, res, next) => {
|
|
try {
|
|
res.json(await listCategories());
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
router.post('/catalog/categories', verifyToken, async (req, res, next) => {
|
|
try {
|
|
res.status(201).json(await createCategory(req.body || {}));
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
router.delete('/catalog/categories/:id', verifyToken, async (req, res, next) => {
|
|
try {
|
|
await deleteCategory(req.params.id);
|
|
res.status(204).end();
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
router.get('/catalog/products', verifyToken, async (req, res, next) => {
|
|
try {
|
|
res.json(await listProducts());
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
router.post('/catalog/products', verifyToken, async (req, res, next) => {
|
|
try {
|
|
res.status(201).json(await createProduct(req.body || {}));
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
router.delete('/catalog/products/:id', verifyToken, async (req, res, next) => {
|
|
try {
|
|
await deleteProduct(req.params.id);
|
|
res.status(204).end();
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
router.get('/catalog/consumption-references', verifyToken, async (req, res, next) => {
|
|
try {
|
|
res.json(await listConsumptionReferences());
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
router.post('/catalog/consumption-references', verifyToken, async (req, res, next) => {
|
|
try {
|
|
res.status(201).json(await createConsumptionReference(req.body || {}));
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
router.post('/catalog/product-compositions/import', verifyToken, async (req, res, next) => {
|
|
try {
|
|
res.status(201).json(await importTinyProductCompositionExport(req.body || {}));
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
router.delete('/catalog/consumption-references/:id', verifyToken, async (req, res, next) => {
|
|
try {
|
|
await deleteConsumptionReference(req.params.id);
|
|
res.status(204).end();
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|