@@ -36,7 +36,7 @@ module.exports = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const preferredLocations = [];
|
const preferredLocations = [];
|
||||||
if (policies.preferredLocations && Array.isArray(policies.preferredLocations)) {
|
if (policies && policies.preferredLocations && Array.isArray(policies.preferredLocations)) {
|
||||||
for (const preferredLocation of policies.preferredLocations) {
|
for (const preferredLocation of policies.preferredLocations) {
|
||||||
preferredLocations.push({ id: preferredLocation.id, type: preferredLocation.type });
|
preferredLocations.push({ id: preferredLocation.id, type: preferredLocation.type });
|
||||||
}
|
}
|
||||||
@@ -112,19 +112,21 @@ module.exports = {
|
|||||||
orderTracking: policies.orderTracking || inventoryData.policies.orderTracking,
|
orderTracking: policies.orderTracking || inventoryData.policies.orderTracking,
|
||||||
alerting: {
|
alerting: {
|
||||||
lowestStockLevel:
|
lowestStockLevel:
|
||||||
policies.alerting && policies.alerting.lowestStockLevel
|
policies.alerting && policies.alerting.lowestStockLevel !== undefined
|
||||||
? policies.alerting.lowestStockLevel
|
? policies.alerting.lowestStockLevel
|
||||||
: inventoryData.policies.alerting.lowestStockLevel,
|
: inventoryData.policies.alerting.lowestStockLevel,
|
||||||
highestStockLevel:
|
highestStockLevel:
|
||||||
policies.alerting && policies.alerting.highestStockLevel
|
policies.alerting && policies.alerting.highestStockLevel !== undefined
|
||||||
? policies.alerting.highestStockLevel
|
? policies.alerting.highestStockLevel
|
||||||
: inventoryData.policies.alerting.highestStockLevel,
|
: inventoryData.policies.alerting.highestStockLevel,
|
||||||
alertStockLevel:
|
alertStockLevel:
|
||||||
policies.alerting && policies.alerting.alertStockLevel
|
policies.alerting && policies.alerting.alertStockLevel !== undefined
|
||||||
? policies.alerting.alertStockLevel
|
? policies.alerting.alertStockLevel
|
||||||
: inventoryData.policies.alerting.alertStockLevel,
|
: inventoryData.policies.alerting.alertStockLevel,
|
||||||
reOrderLevel:
|
reOrderLevel:
|
||||||
policies.alerting && policies.alerting.reOrderLevel ? policies.alerting.reOrderLevel : inventoryData.policies.alerting.reOrderLevel,
|
policies.alerting && policies.alerting.reOrderLevel !== undefined
|
||||||
|
? policies.alerting.reOrderLevel
|
||||||
|
: inventoryData.policies.alerting.reOrderLevel,
|
||||||
},
|
},
|
||||||
replenishment: policies.replenishment || inventoryData.policies.replenishment,
|
replenishment: policies.replenishment || inventoryData.policies.replenishment,
|
||||||
preferredLocations: preferredLocations,
|
preferredLocations: preferredLocations,
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ module.exports = {
|
|||||||
putItem: async (req, res, next) => {
|
putItem: async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (!id || mongoose.isValidObjectId(id)) {
|
if (!id || !mongoose.isValidObjectId(id)) {
|
||||||
res.status(400).send("Missing/Invalid id param");
|
res.status(400).send("Missing/Invalid id param");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -227,18 +227,23 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const subLevelObj = await Sublevel.findById(subLevel);
|
const subLevelObj = await Sublevel.findById(subLevel);
|
||||||
const itemAssociation = await ItemAssociation.findOne({ item_id: item._id, sub_level_id: subLevelObj._id });
|
let itemAssociation = await ItemAssociation.findOne({ item_id: item._id, sub_level_id: subLevelObj._id });
|
||||||
|
if (!itemAssociation) {
|
||||||
|
itemAssociation = await ItemAssociation.create({ item_id: item._id, sub_level_id: subLevelObj._id });
|
||||||
|
}
|
||||||
itemAssociation.totalQuantity = itemAssociation.totalQuantity + putQuantity;
|
itemAssociation.totalQuantity = itemAssociation.totalQuantity + putQuantity;
|
||||||
itemAssociation.availableQuantity = itemAssociation.availableQuantity + putQuantity;
|
itemAssociation.availableQuantity = itemAssociation.availableQuantity + putQuantity;
|
||||||
await itemAssociation.save();
|
await itemAssociation.save();
|
||||||
|
|
||||||
await PutItemTransaction.create({
|
const itemTransaction = await PutItemTransaction.create({
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
performedOn: item,
|
performedOn: item,
|
||||||
performedBy: res.locals.user,
|
performedBy: res.locals.user,
|
||||||
putQuantity: putQuantity,
|
putQuantity: putQuantity,
|
||||||
subLevel: subLevelObj,
|
subLevel: subLevelObj,
|
||||||
});
|
});
|
||||||
|
res.send({ success: true, data: { itemAssociation, itemTransaction } });
|
||||||
|
res.send({ success: true, data: { itemAssociation, itemTransaction } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -247,7 +252,7 @@ module.exports = {
|
|||||||
pickItem: async (req, res, next) => {
|
pickItem: async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (!id || mongoose.isValidObjectId(id)) {
|
if (!id || !mongoose.isValidObjectId(id)) {
|
||||||
res.status(400).send("Missing/Invalid id param");
|
res.status(400).send("Missing/Invalid id param");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -265,18 +270,22 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const subLevelObj = await Sublevel.findById(subLevel);
|
const subLevelObj = await Sublevel.findById(subLevel);
|
||||||
const itemAssociation = await ItemAssociation.findOne({ item_id: item._id, sub_level_id: subLevelObj._id });
|
let itemAssociation = await ItemAssociation.findOne({ item_id: item._id, sub_level_id: subLevelObj._id });
|
||||||
|
if (!itemAssociation) {
|
||||||
|
itemAssociation = await ItemAssociation.create({ item_id: item._id, sub_level_id: subLevelObj._id });
|
||||||
|
}
|
||||||
itemAssociation.totalQuantity = itemAssociation.totalQuantity - pickupQuantity;
|
itemAssociation.totalQuantity = itemAssociation.totalQuantity - pickupQuantity;
|
||||||
itemAssociation.availableQuantity = itemAssociation.availableQuantity - pickupQuantity;
|
itemAssociation.availableQuantity = itemAssociation.availableQuantity - pickupQuantity;
|
||||||
await itemAssociation.save();
|
await itemAssociation.save();
|
||||||
|
|
||||||
await PickItemTransaction.create({
|
const itemTransaction = await PickItemTransaction.create({
|
||||||
type: "PICK",
|
type: "PICK",
|
||||||
performedOn: item,
|
performedOn: item,
|
||||||
performedBy: res.locals.user,
|
performedBy: res.locals.user,
|
||||||
pickupQuantity: pickupQuantity,
|
pickupQuantity: pickupQuantity,
|
||||||
subLevel: subLevelObj,
|
subLevel: subLevelObj,
|
||||||
});
|
});
|
||||||
|
res.send({ success: true, data: { itemAssociation, itemTransaction } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -285,7 +294,7 @@ module.exports = {
|
|||||||
reserveItem: async (req, res, next) => {
|
reserveItem: async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (!id || mongoose.isValidObjectId(id)) {
|
if (!id || !mongoose.isValidObjectId(id)) {
|
||||||
res.status(400).send("Missing/Invalid id param");
|
res.status(400).send("Missing/Invalid id param");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -303,11 +312,15 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const itemAssociation = await ItemAssociation.findOne({ item_id: item._id, availableQuantity: { $gte: reserveQuantity } });
|
const itemAssociation = await ItemAssociation.findOne({ item_id: item._id, availableQuantity: { $gte: reserveQuantity } });
|
||||||
|
if (!itemAssociation) {
|
||||||
|
res.status(500).send("Quantity unavailable");
|
||||||
|
return;
|
||||||
|
}
|
||||||
itemAssociation.reservedQuantity = itemAssociation.reservedQuantity + reserveQuantity;
|
itemAssociation.reservedQuantity = itemAssociation.reservedQuantity + reserveQuantity;
|
||||||
itemAssociation.availableQuantity = itemAssociation.availableQuantity - reserveQuantity;
|
itemAssociation.availableQuantity = itemAssociation.availableQuantity - reserveQuantity;
|
||||||
await itemAssociation.save();
|
await itemAssociation.save();
|
||||||
|
|
||||||
await ReserveItemTransaction.create({
|
const itemTransaction = await ReserveItemTransaction.create({
|
||||||
type: "RESERVE",
|
type: "RESERVE",
|
||||||
performedOn: item,
|
performedOn: item,
|
||||||
performedBy: res.locals.user,
|
performedBy: res.locals.user,
|
||||||
@@ -315,6 +328,7 @@ module.exports = {
|
|||||||
job: job,
|
job: job,
|
||||||
pickupDate: Date.parse(pickupDate),
|
pickupDate: Date.parse(pickupDate),
|
||||||
});
|
});
|
||||||
|
res.send({ success: true, data: { itemAssociation, itemTransaction } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -323,7 +337,7 @@ module.exports = {
|
|||||||
checkInItem: async (req, res, next) => {
|
checkInItem: async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (!id || mongoose.isValidObjectId(id)) {
|
if (!id || !mongoose.isValidObjectId(id)) {
|
||||||
res.status(400).send("Missing/Invalid id param");
|
res.status(400).send("Missing/Invalid id param");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -340,7 +354,7 @@ module.exports = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await CheckInItemTransaction.create({
|
const itemTransaction = await CheckInItemTransaction.create({
|
||||||
type: "CHECK-IN",
|
type: "CHECK-IN",
|
||||||
performedOn: item,
|
performedOn: item,
|
||||||
performedBy: res.locals.user,
|
performedBy: res.locals.user,
|
||||||
@@ -348,6 +362,7 @@ module.exports = {
|
|||||||
hasIssue: hasIssue,
|
hasIssue: hasIssue,
|
||||||
issueDescription: hasIssue ? issueDescription : "",
|
issueDescription: hasIssue ? issueDescription : "",
|
||||||
});
|
});
|
||||||
|
res.send({ success: true, data: { itemTransaction } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -356,7 +371,7 @@ module.exports = {
|
|||||||
checkOutItem: async (req, res, next) => {
|
checkOutItem: async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (!id || mongoose.isValidObjectId(id)) {
|
if (!id || !mongoose.isValidObjectId(id)) {
|
||||||
res.status(400).send("Missing/Invalid id param");
|
res.status(400).send("Missing/Invalid id param");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -373,7 +388,7 @@ module.exports = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await CheckOutItemTransaction.create({
|
const itemTransaction = await CheckOutItemTransaction.create({
|
||||||
type: "CHECK-OUT",
|
type: "CHECK-OUT",
|
||||||
performedOn: item,
|
performedOn: item,
|
||||||
performedBy: res.locals.user,
|
performedBy: res.locals.user,
|
||||||
@@ -381,6 +396,7 @@ module.exports = {
|
|||||||
job: job,
|
job: job,
|
||||||
usageReason: usageReason ? usageReason : "",
|
usageReason: usageReason ? usageReason : "",
|
||||||
});
|
});
|
||||||
|
res.send({ success: true, data: { itemTransaction } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -389,7 +405,7 @@ module.exports = {
|
|||||||
reportItem: async (req, res, next) => {
|
reportItem: async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (!id || mongoose.isValidObjectId(id)) {
|
if (!id || !mongoose.isValidObjectId(id)) {
|
||||||
res.status(400).send("Missing/Invalid id param");
|
res.status(400).send("Missing/Invalid id param");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -406,13 +422,14 @@ module.exports = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ReportItemTransaction.create({
|
const itemTransaction = await ReportItemTransaction.create({
|
||||||
type: "REPORT",
|
type: "REPORT",
|
||||||
performedOn: item,
|
performedOn: item,
|
||||||
performedBy: res.locals.user,
|
performedBy: res.locals.user,
|
||||||
reportingFor: reportingFor,
|
reportingFor: reportingFor,
|
||||||
details: details ? details : "",
|
details: details ? details : "",
|
||||||
});
|
});
|
||||||
|
res.send({ success: true, data: { itemTransaction } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -421,7 +438,7 @@ module.exports = {
|
|||||||
adjustItem: async (req, res, next) => {
|
adjustItem: async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (!id || mongoose.isValidObjectId(id)) {
|
if (!id || !mongoose.isValidObjectId(id)) {
|
||||||
res.status(400).send("Missing/Invalid id param");
|
res.status(400).send("Missing/Invalid id param");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -447,7 +464,7 @@ module.exports = {
|
|||||||
itemAssociation.availableQuantity = itemAssociation.availableQuantity - totalAdjustment;
|
itemAssociation.availableQuantity = itemAssociation.availableQuantity - totalAdjustment;
|
||||||
await itemAssociation.save();
|
await itemAssociation.save();
|
||||||
|
|
||||||
await AdjustItemTransaction.create({
|
const itemTransaction = await AdjustItemTransaction.create({
|
||||||
type: "ADJUST",
|
type: "ADJUST",
|
||||||
performedOn: item,
|
performedOn: item,
|
||||||
performedBy: res.locals.user,
|
performedBy: res.locals.user,
|
||||||
@@ -458,6 +475,7 @@ module.exports = {
|
|||||||
totalAdjustment,
|
totalAdjustment,
|
||||||
newAdjustedQuantity: itemAssociation.totalQuantity,
|
newAdjustedQuantity: itemAssociation.totalQuantity,
|
||||||
});
|
});
|
||||||
|
res.send({ success: true, data: { itemAssociation, itemTransaction } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ module.exports = {
|
|||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (!mongoose.isValidObjectId(id)) {
|
if (!mongoose.isValidObjectId(id)) {
|
||||||
res.status(400).send({ success: false, error: "Invalid data for user ID" });
|
res.status(400).send({ success: false, error: "Invalid data for user ID" });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -209,13 +210,15 @@ module.exports = {
|
|||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (!mongoose.isValidObjectId(id)) {
|
if (!mongoose.isValidObjectId(id)) {
|
||||||
res.status(400).send({ success: false, error: "Invalid data for user ID" });
|
res.status(400).send({ success: false, error: "Invalid data for user ID" });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { email, fullName, password } = req.body;
|
const { email, fullName, password } = req.body;
|
||||||
try {
|
try {
|
||||||
const user = await User.findById(id);
|
const user = await User.findById(id);
|
||||||
if (user) {
|
if (!user) {
|
||||||
res.status(404).send({ success: false, error: "User not found" });
|
res.status(404).send({ success: false, error: "User not found" });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const salt = await bcrypt.genSalt();
|
const salt = await bcrypt.genSalt();
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ const { SuperAdminCheck, AuthenticateMiddleware } = require("./utils/authorize")
|
|||||||
router.post("/register", controller.registerUser);
|
router.post("/register", controller.registerUser);
|
||||||
router.post("/login", controller.loginUser);
|
router.post("/login", controller.loginUser);
|
||||||
|
|
||||||
|
router.post("/:user/add-access", AuthenticateMiddleware, SuperAdminCheck, controller.addUserAccessControl);
|
||||||
|
router.post("/:user/remove-access", AuthenticateMiddleware, SuperAdminCheck, controller.removeUserAccessControl);
|
||||||
|
router.get("/allowed-ui-modules", AuthenticateMiddleware, controller.getUIAccessControl);
|
||||||
|
|
||||||
router.get("/all", AuthenticateMiddleware, SuperAdminCheck, controller.getAllUsers);
|
router.get("/all", AuthenticateMiddleware, SuperAdminCheck, controller.getAllUsers);
|
||||||
router.get("/:id", AuthenticateMiddleware, SuperAdminCheck, controller.getUserById);
|
router.get("/:id", AuthenticateMiddleware, SuperAdminCheck, controller.getUserById);
|
||||||
router.post("/create", AuthenticateMiddleware, SuperAdminCheck, controller.createUser);
|
router.post("/create", AuthenticateMiddleware, SuperAdminCheck, controller.createUser);
|
||||||
router.post("/:id", AuthenticateMiddleware, SuperAdminCheck, controller.updateUser);
|
router.post("/:id", AuthenticateMiddleware, SuperAdminCheck, controller.updateUser);
|
||||||
|
|
||||||
router.post("/:user/add-access", AuthenticateMiddleware, SuperAdminCheck, controller.addUserAccessControl);
|
|
||||||
router.post("/:user/remove-access", AuthenticateMiddleware, SuperAdminCheck, controller.removeUserAccessControl);
|
|
||||||
router.get("/allowed-ui-modules", AuthenticateMiddleware, controller.getUIAccessControl);
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ module.exports = {
|
|||||||
|
|
||||||
const result = await UserPermission.find(
|
const result = await UserPermission.find(
|
||||||
{},
|
{},
|
||||||
{ id: 1, name: 1, inventoryScopes: 1, warehouseScopes: 1, actions: 1 },
|
{ id: 1, name: 1, inventoryScopes: 1, warehouseScopes: 1, actions: 1, allowedUIModules: 1 },
|
||||||
{ skip: page * perPage, limit: perPage }
|
{ skip: page * perPage, limit: perPage }
|
||||||
);
|
);
|
||||||
res.send({ success: true, data: result });
|
res.send({ success: true, data: result });
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const getValidPermissions = async (permissions) => {
|
|||||||
const verifiedPermissions = permissions.filter((permission) => mongoose.isValidObjectId(permission));
|
const verifiedPermissions = permissions.filter((permission) => mongoose.isValidObjectId(permission));
|
||||||
if (verifiedPermissions.length === 0) return [];
|
if (verifiedPermissions.length === 0) return [];
|
||||||
const permissionObjects = await UserPermission.find({
|
const permissionObjects = await UserPermission.find({
|
||||||
id: { $in: verifiedPermissions },
|
_id: { $in: verifiedPermissions },
|
||||||
}).select({ _id: 1 });
|
}).select({ _id: 1 });
|
||||||
return permissionObjects.map((_) => _._id);
|
return permissionObjects.map((_) => _._id);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ module.exports = {
|
|||||||
try {
|
try {
|
||||||
const widgetFamilyData = await WidgetFamily.findById(id);
|
const widgetFamilyData = await WidgetFamily.findById(id);
|
||||||
if (!widgetFamilyData) {
|
if (!widgetFamilyData) {
|
||||||
res.status(404);
|
res.status(404).send({ success: false, error: "Widget not found" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.send({ success: true, data: widgetFamilyData });
|
res.send({ success: true, data: widgetFamilyData });
|
||||||
|
|||||||
Reference in New Issue
Block a user