Merge branch 'dev' into feat/auth
This commit is contained in:
94
src/controller/area.controller.js
Normal file
94
src/controller/area.controller.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const Area = require("../models/Area");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Gets the area data by `id`
|
||||
*/
|
||||
getAreaByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const areaData = await Area.findById(id);
|
||||
if (!areaData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(areaData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a area
|
||||
*/
|
||||
createArea: async (req, res, next) => {
|
||||
const { name, type, specs, zone_id } = req.body;
|
||||
|
||||
if (!(name && type)) {
|
||||
res.status(400).send("Missing params param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const areaData = new Area({
|
||||
name,
|
||||
type,
|
||||
specs,
|
||||
zone_id: mongoose.Types.ObjectId(zone_id),
|
||||
});
|
||||
|
||||
await areaData.save();
|
||||
if (!areaData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(areaData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a areas detail
|
||||
*/
|
||||
updateAreaByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
const { name, type, specs, zone_id } = req.body;
|
||||
|
||||
if (!(name || type || specs || zone_id)) {
|
||||
res.status(400).send("Missing data in body");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const areaData = await Area.findById(id);
|
||||
if (!areaData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name) areaData.name = name;
|
||||
if (type) areaData.type = type;
|
||||
if (specs) areaData.specs = specs;
|
||||
if (zone_id) areaData.zone_id = mongoose.Types.ObjectId(zone_id);
|
||||
|
||||
await areaData.save();
|
||||
req.send(areaData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
19
src/controller/area.router.js
Normal file
19
src/controller/area.router.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const router = require("express").Router();
|
||||
const controller = require("./area.controller");
|
||||
|
||||
/**
|
||||
* @route /area/:id
|
||||
*/
|
||||
router.get("/:id", controller.getAreaByID);
|
||||
|
||||
/**
|
||||
* @route /area/
|
||||
*/
|
||||
router.post("/", controller.createArea);
|
||||
|
||||
/**
|
||||
* @route /area/
|
||||
*/
|
||||
router.patch("/:id", controller.updateAreaByID);
|
||||
|
||||
module.exports = router;
|
||||
96
src/controller/bay.controller.js
Normal file
96
src/controller/bay.controller.js
Normal file
@@ -0,0 +1,96 @@
|
||||
const Bay = require("../models/Bay");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Gets the bay data by `id`
|
||||
*/
|
||||
getBayByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const bayData = await Bay.findById(id);
|
||||
if (!bayData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(bayData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a bay
|
||||
*/
|
||||
createBay: async (req, res, next) => {
|
||||
const { name, number, type, specs, row_id } = req.body;
|
||||
|
||||
if (!(name && type && number)) {
|
||||
res.status(400).send("Missing params param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const bayData = new Bay({
|
||||
name,
|
||||
number: parseInt(number),
|
||||
type,
|
||||
specs,
|
||||
row_id: mongoose.Types.ObjectId(row_id),
|
||||
});
|
||||
|
||||
await bayData.save();
|
||||
if (!bayData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(bayData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a bays detail
|
||||
*/
|
||||
updateBayByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
const { name, number, type, specs, row_id } = req.body;
|
||||
|
||||
if (!(name || number || type || specs || row_id)) {
|
||||
res.status(400).send("Missing data in body");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const bayData = await Bay.findById(id);
|
||||
if (!bayData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name) bayData.name = name;
|
||||
if (number) bayData.number = parseInt(number);
|
||||
if (type) bayData.type = type;
|
||||
if (specs) bayData.specs = specs;
|
||||
if (row_id) bayData.row_id = mongoose.Types.ObjectId(row_id);
|
||||
|
||||
await bayData.save();
|
||||
req.send(bayData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
19
src/controller/bay.router.js
Normal file
19
src/controller/bay.router.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const router = require("express").Router();
|
||||
const controller = require("./bay.controller");
|
||||
|
||||
/**
|
||||
* @route /bay/:id
|
||||
*/
|
||||
router.get("/:id", controller.getBayByID);
|
||||
|
||||
/**
|
||||
* @route /bay/
|
||||
*/
|
||||
router.post("/", controller.createBay);
|
||||
|
||||
/**
|
||||
* @route /bay/
|
||||
*/
|
||||
router.patch("/:id", controller.updateBayByID);
|
||||
|
||||
module.exports = router;
|
||||
93
src/controller/company.controller.js
Normal file
93
src/controller/company.controller.js
Normal file
@@ -0,0 +1,93 @@
|
||||
const Company = require("../models/Company");
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Gets the company data by `id`
|
||||
*/
|
||||
getCompanyByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const companyData = await Company.findById(id);
|
||||
if (!companyData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(companyData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a company
|
||||
*/
|
||||
createCompany: async (req, res, next) => {
|
||||
const { name, address, contact_info, business_info } = req.body;
|
||||
|
||||
if (!(name && address)) {
|
||||
res.status(400).send("Missing params param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const companyData = new Company({
|
||||
name,
|
||||
address,
|
||||
contact_info,
|
||||
business_info,
|
||||
});
|
||||
|
||||
await companyData.save();
|
||||
if (!companyData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(companyData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a companys detail
|
||||
*/
|
||||
updateCompanyByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
const { name, address, contact_info, business_info } = req.body;
|
||||
|
||||
if (!(name || address || contact_info || business_info)) {
|
||||
res.status(400).send("Missing data in body");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const companyData = await Company.findById(id);
|
||||
if (!companyData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name) companyData.name = name;
|
||||
if (address) companyData.address = address;
|
||||
if (contact_info) companyData.contact_info = contact_info;
|
||||
if (business_info) companyData.business_info = business_info;
|
||||
|
||||
await companyData.save();
|
||||
req.send(companyData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
19
src/controller/company.router.js
Normal file
19
src/controller/company.router.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const router = require("express").Router();
|
||||
const controller = require("./company.controller");
|
||||
|
||||
/**
|
||||
* @route /company/:id
|
||||
*/
|
||||
router.get("/:id", controller.getCompanyByID);
|
||||
|
||||
/**
|
||||
* @route /company/
|
||||
*/
|
||||
router.post("/", controller.createCompany);
|
||||
|
||||
/**
|
||||
* @route /company/
|
||||
*/
|
||||
router.patch("/:id", controller.updateCompanyByID);
|
||||
|
||||
module.exports = router;
|
||||
@@ -4,9 +4,25 @@ const userRoleRouter = require("./userRole.router");
|
||||
const userPermissionRouter = require("./userPermission.router");
|
||||
const { AuthenticateMiddleware } = require("../config/auth");
|
||||
|
||||
router.use("/user", userRouter);
|
||||
const companyRouter = require("./company.router");
|
||||
const warehouseRouter = require("./warehouse.router");
|
||||
const zoneRouter = require("./zone.router");
|
||||
const areaRouter = require("./area.router");
|
||||
const bayRouter = require("./bay.router");
|
||||
const rowRouter = require("./row.router");
|
||||
const levelRouter = require("./level.router");
|
||||
|
||||
router.use("/user-role", AuthenticateMiddleware, userRoleRouter);
|
||||
router.use("/user-permission", AuthenticateMiddleware, userPermissionRouter);
|
||||
router.use("/user", userRouter);
|
||||
router.use("/company", companyRouter);
|
||||
router.use("/warehouse", warehouseRouter);
|
||||
router.use("/zone", zoneRouter);
|
||||
router.use("/area", areaRouter);
|
||||
router.use("/bay", bayRouter);
|
||||
router.use("/row", rowRouter);
|
||||
router.use("/level", levelRouter);
|
||||
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
res.send({ success: true, message: "Hello world" });
|
||||
|
||||
94
src/controller/level.controller.js
Normal file
94
src/controller/level.controller.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const Level = require("../models/Level");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Gets the level data by `id`
|
||||
*/
|
||||
getLevelByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const levelData = await Level.findById(id);
|
||||
if (!levelData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(levelData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a level
|
||||
*/
|
||||
createLevel: async (req, res, next) => {
|
||||
const { name, number, specs, bay_id } = req.body;
|
||||
|
||||
if (!(name && number)) {
|
||||
res.status(400).send("Missing params param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const levelData = new Level({
|
||||
name,
|
||||
number: parseInt(number),
|
||||
specs,
|
||||
bay_id: mongoose.Types.ObjectId(bay_id),
|
||||
});
|
||||
|
||||
await levelData.save();
|
||||
if (!levelData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(levelData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a levels detail
|
||||
*/
|
||||
updateLevelByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
const { name, number, specs, bay_id } = req.body;
|
||||
|
||||
if (!(name || number || specs || bay_id)) {
|
||||
res.status(400).send("Missing data in body");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const levelData = await Level.findById(id);
|
||||
if (!levelData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name) levelData.name = name;
|
||||
if (number) levelData.number = parseInt(number);
|
||||
if (specs) levelData.specs = specs;
|
||||
if (bay_id) levelData.bay_id = mongoose.Types.ObjectId(bay_id);
|
||||
|
||||
await levelData.save();
|
||||
req.send(levelData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
19
src/controller/level.router.js
Normal file
19
src/controller/level.router.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const router = require("express").Router();
|
||||
const controller = require("./level.controller");
|
||||
|
||||
/**
|
||||
* @route /level/:id
|
||||
*/
|
||||
router.get("/:id", controller.getLevelByID);
|
||||
|
||||
/**
|
||||
* @route /level/
|
||||
*/
|
||||
router.post("/", controller.createLevel);
|
||||
|
||||
/**
|
||||
* @route /level/
|
||||
*/
|
||||
router.patch("/:id", controller.updateLevelByID);
|
||||
|
||||
module.exports = router;
|
||||
94
src/controller/row.controller.js
Normal file
94
src/controller/row.controller.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const Row = require("../models/Row");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Gets the row data by `id`
|
||||
*/
|
||||
getRowByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const rowData = await Row.findById(id);
|
||||
if (!rowData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(rowData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a row
|
||||
*/
|
||||
createRow: async (req, res, next) => {
|
||||
const { name, number, specs, area_id } = req.body;
|
||||
|
||||
if (!(name && number)) {
|
||||
res.status(400).send("Missing params param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const rowData = new Row({
|
||||
name,
|
||||
number: parseInt(number),
|
||||
specs,
|
||||
area_id: mongoose.Types.ObjectId(area_id),
|
||||
});
|
||||
|
||||
await rowData.save();
|
||||
if (!rowData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(rowData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a rows detail
|
||||
*/
|
||||
updateRowByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
const { name, number, specs, area_id } = req.body;
|
||||
|
||||
if (!(name || number || specs || area_id)) {
|
||||
res.status(400).send("Missing data in body");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const rowData = await Row.findById(id);
|
||||
if (!rowData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name) rowData.name = name;
|
||||
if (number) rowData.number = parseInt(number);
|
||||
if (specs) rowData.specs = specs;
|
||||
if (area_id) rowData.area_id = mongoose.Types.ObjectId(area_id);
|
||||
|
||||
await rowData.save();
|
||||
req.send(rowData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
19
src/controller/row.router.js
Normal file
19
src/controller/row.router.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const router = require("express").Router();
|
||||
const controller = require("./row.controller");
|
||||
|
||||
/**
|
||||
* @route /row/:id
|
||||
*/
|
||||
router.get("/:id", controller.getRowByID);
|
||||
|
||||
/**
|
||||
* @route /row/
|
||||
*/
|
||||
router.post("/", controller.createRow);
|
||||
|
||||
/**
|
||||
* @route /row/
|
||||
*/
|
||||
router.patch("/:id", controller.updateRowByID);
|
||||
|
||||
module.exports = router;
|
||||
94
src/controller/warehouse.controller.js
Normal file
94
src/controller/warehouse.controller.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const Warehouse = require("../models/Warehouse");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Gets the warehouse data by `id`
|
||||
*/
|
||||
getWarehouseByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const warehouseData = await Warehouse.findById(id);
|
||||
if (!warehouseData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(warehouseData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a warehouse
|
||||
*/
|
||||
createWarehouse: async (req, res, next) => {
|
||||
const { name, address, specs, company_id } = req.body;
|
||||
|
||||
if (!(name && address)) {
|
||||
res.status(400).send("Missing params param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const warehouseData = new Warehouse({
|
||||
name,
|
||||
address,
|
||||
specs,
|
||||
company_id: mongoose.Types.ObjectId(company_id),
|
||||
});
|
||||
|
||||
await warehouseData.save();
|
||||
if (!warehouseData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(warehouseData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a warehouses detail
|
||||
*/
|
||||
updateWarehouseByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
const { name, address, specs, company_id } = req.body;
|
||||
|
||||
if (!(name || address || specs || company_id)) {
|
||||
res.status(400).send("Missing data in body");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const warehouseData = await Warehouse.findById(id);
|
||||
if (!warehouseData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name) warehouseData.name = name;
|
||||
if (address) warehouseData.address = address;
|
||||
if (specs) warehouseData.specs = specs;
|
||||
if (company_id) warehouseData.company_id = mongoose.Types.ObjectId(company_id);
|
||||
|
||||
await warehouseData.save();
|
||||
req.send(warehouseData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
19
src/controller/warehouse.router.js
Normal file
19
src/controller/warehouse.router.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const router = require("express").Router();
|
||||
const controller = require("./warehouse.controller");
|
||||
|
||||
/**
|
||||
* @route /warehouse/:id
|
||||
*/
|
||||
router.get("/:id", controller.getWarehouseByID);
|
||||
|
||||
/**
|
||||
* @route /warehouse/
|
||||
*/
|
||||
router.post("/", controller.createWarehouse);
|
||||
|
||||
/**
|
||||
* @route /warehouse/
|
||||
*/
|
||||
router.patch("/:id", controller.updateWarehouseByID);
|
||||
|
||||
module.exports = router;
|
||||
94
src/controller/zone.controller.js
Normal file
94
src/controller/zone.controller.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const Zone = require("../models/Zone");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Gets the zone data by `id`
|
||||
*/
|
||||
getZoneByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const zoneData = await Zone.findById(id);
|
||||
if (!zoneData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(zoneData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a zone
|
||||
*/
|
||||
createZone: async (req, res, next) => {
|
||||
const { name, type, specs, warehouse_id } = req.body;
|
||||
|
||||
if (!(name && type)) {
|
||||
res.status(400).send("Missing params param");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const zoneData = new Zone({
|
||||
name,
|
||||
type,
|
||||
specs,
|
||||
warehouse_id: mongoose.Types.ObjectId(warehouse_id),
|
||||
});
|
||||
|
||||
await zoneData.save();
|
||||
if (!zoneData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
req.send(zoneData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a zones detail
|
||||
*/
|
||||
updateZoneByID: async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send("Missing id param");
|
||||
return;
|
||||
}
|
||||
|
||||
const { name, type, specs, warehouse_id } = req.body;
|
||||
|
||||
if (!(name || type || specs || warehouse_id)) {
|
||||
res.status(400).send("Missing data in body");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const zoneData = await Zone.findById(id);
|
||||
if (!zoneData) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name) zoneData.name = name;
|
||||
if (type) zoneData.type = type;
|
||||
if (specs) zoneData.specs = specs;
|
||||
if (warehouse_id) zoneData.warehouse_id = mongoose.Types.ObjectId(warehouse_id);
|
||||
|
||||
await zoneData.save();
|
||||
req.send(zoneData);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
19
src/controller/zone.router.js
Normal file
19
src/controller/zone.router.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const router = require("express").Router();
|
||||
const controller = require("./zone.controller");
|
||||
|
||||
/**
|
||||
* @route /zone/:id
|
||||
*/
|
||||
router.get("/:id", controller.getZoneByID);
|
||||
|
||||
/**
|
||||
* @route /zone/
|
||||
*/
|
||||
router.post("/", controller.createZone);
|
||||
|
||||
/**
|
||||
* @route /zone/
|
||||
*/
|
||||
router.patch("/:id", controller.updateZoneByID);
|
||||
|
||||
module.exports = router;
|
||||
@@ -9,7 +9,7 @@ const schema = new mongoose.Schema(
|
||||
},
|
||||
number: {
|
||||
required: true,
|
||||
type: String,
|
||||
type: Number,
|
||||
trim: true,
|
||||
},
|
||||
specs: {
|
||||
@@ -17,6 +17,10 @@ const schema = new mongoose.Schema(
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
bay_id: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "Bay",
|
||||
},
|
||||
sub_levels: [
|
||||
{
|
||||
type: {
|
||||
|
||||
Reference in New Issue
Block a user