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