46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
import express from "express";
|
|
import { isAuthenticated } from "../../keycloak.js";
|
|
import { parseStringIfNumber } from "../../util/index.js";
|
|
|
|
const router = express.Router();
|
|
import {
|
|
listPartStocksRouteHandler,
|
|
getPartStockRouteHandler,
|
|
editPartStockRouteHandler,
|
|
newPartStockRouteHandler,
|
|
} from "../../services/partstocks/index.js";
|
|
|
|
// list of partStocks
|
|
router.get("/", isAuthenticated, (req, res) => {
|
|
const { page, limit, property } = req.query;
|
|
|
|
const allowedFilters = ["country"];
|
|
|
|
const filter = {};
|
|
|
|
for (const [key, value] of Object.entries(req.query)) {
|
|
for (var i = 0; i < allowedFilters.length; i++) {
|
|
if (key == allowedFilters[i]) {
|
|
filter[key] = parseStringIfNumber(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
listPartStocksRouteHandler(req, res, page, limit, property, filter);
|
|
});
|
|
|
|
router.post("/", isAuthenticated, (req, res) => {
|
|
newPartStockRouteHandler(req, res);
|
|
});
|
|
|
|
router.get("/:id", isAuthenticated, (req, res) => {
|
|
getPartStockRouteHandler(req, res);
|
|
});
|
|
|
|
// update printer info
|
|
router.put("/:id", isAuthenticated, async (req, res) => {
|
|
editPartStockRouteHandler(req, res);
|
|
});
|
|
|
|
export default router;
|