feat: added check-in, check-out & report apis
This commit is contained in:
@@ -68,6 +68,8 @@ const ItemTransactionTypes = [
|
|||||||
"RESERVE"
|
"RESERVE"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const ReportItemForTypes = ["LOCATION", "ISSUE", "INCIDENT"];
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
UserActions,
|
UserActions,
|
||||||
InventoryScopes,
|
InventoryScopes,
|
||||||
@@ -85,4 +87,5 @@ module.exports = {
|
|||||||
AUTHENTICATION_FAILURE_ERROR_MESSAGE,
|
AUTHENTICATION_FAILURE_ERROR_MESSAGE,
|
||||||
AUTHORIZATION_FAILURE_ERROR_MESSAGE,
|
AUTHORIZATION_FAILURE_ERROR_MESSAGE,
|
||||||
ItemTransactionTypes,
|
ItemTransactionTypes,
|
||||||
|
ReportItemForTypes,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ const {
|
|||||||
PickItemTransaction,
|
PickItemTransaction,
|
||||||
PutItemTransaction,
|
PutItemTransaction,
|
||||||
ReserveItemTransaction,
|
ReserveItemTransaction,
|
||||||
// CheckInItemTransaction,
|
CheckInItemTransaction,
|
||||||
// CheckOutItemTransaction,
|
CheckOutItemTransaction,
|
||||||
// ReportItemTransaction,
|
ReportItemTransaction,
|
||||||
// AdjustItemTransaction,
|
// AdjustItemTransaction,
|
||||||
} = require("../models/ItemTransaction");
|
} = require("../models/ItemTransaction");
|
||||||
|
|
||||||
const ItemAssociation = require("../models/ItemAssociation");
|
const ItemAssociation = require("../models/ItemAssociation");
|
||||||
const Sublevel = require("../models/Sublevel");
|
const Sublevel = require("../models/Sublevel");
|
||||||
const { InventoryTypes } = require("../config/constants");
|
const { InventoryTypes, ReportItemForTypes } = require("../config/constants");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
@@ -306,7 +306,7 @@ module.exports = {
|
|||||||
await itemAssociation.save();
|
await itemAssociation.save();
|
||||||
|
|
||||||
await ReserveItemTransaction.create({
|
await ReserveItemTransaction.create({
|
||||||
type: "PUT",
|
type: "RESERVE",
|
||||||
performedOn: item,
|
performedOn: item,
|
||||||
performedBy: res.locals.user,
|
performedBy: res.locals.user,
|
||||||
reserveQuantity: reserveQuantity,
|
reserveQuantity: reserveQuantity,
|
||||||
@@ -318,13 +318,99 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
checkInItem: async (req, res, next) => {
|
checkInItem: async (req, res, next) => {
|
||||||
res.status(500).send({ success: false, error: "Not Implemented" });
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
if (!id || mongoose.isValidObjectId(id)) {
|
||||||
|
res.status(400).send("Missing/Invalid id param");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = await Item.findById(id);
|
||||||
|
if (!item) {
|
||||||
|
res.status(404).send("item not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { checkInMeterReading, hasIssue, issueDescription } = req.body;
|
||||||
|
if (!(checkInMeterReading && checkInMeterReading > 0)) {
|
||||||
|
res.status(400).send("Invalid value for checkInMeterReading");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await CheckInItemTransaction.create({
|
||||||
|
type: "CHECK-IN",
|
||||||
|
performedOn: item,
|
||||||
|
performedBy: res.locals.user,
|
||||||
|
checkInMeterReading: checkInMeterReading,
|
||||||
|
hasIssue: hasIssue,
|
||||||
|
issueDescription: hasIssue ? issueDescription : "",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
checkOutItem: async (req, res, next) => {
|
checkOutItem: async (req, res, next) => {
|
||||||
res.status(500).send({ success: false, error: "Not Implemented" });
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
if (!id || mongoose.isValidObjectId(id)) {
|
||||||
|
res.status(400).send("Missing/Invalid id param");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = await Item.findById(id);
|
||||||
|
if (!item) {
|
||||||
|
res.status(404).send("item not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { checkOutMeterReading, job, usageReason } = req.body;
|
||||||
|
if (!(checkOutMeterReading && checkOutMeterReading > 0) || !(job && mongoose.isValidObjectId(job))) {
|
||||||
|
res.status(400).send("Invalid value for checkOutMeterReading/job");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await CheckOutItemTransaction.create({
|
||||||
|
type: "CHECK-OUT",
|
||||||
|
performedOn: item,
|
||||||
|
performedBy: res.locals.user,
|
||||||
|
checkOutMeterReading: checkOutMeterReading,
|
||||||
|
job: job,
|
||||||
|
usageReason: usageReason ? usageReason : "",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
reportItem: async (req, res, next) => {
|
reportItem: async (req, res, next) => {
|
||||||
res.status(500).send({ success: false, error: "Not Implemented" });
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
if (!id || mongoose.isValidObjectId(id)) {
|
||||||
|
res.status(400).send("Missing/Invalid id param");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = await Item.findById(id);
|
||||||
|
if (!item) {
|
||||||
|
res.status(404).send("item not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { reportingFor, details } = req.body;
|
||||||
|
if (!(reportingFor && ReportItemForTypes.includes(reportingFor))) {
|
||||||
|
res.status(400).send("Invalid value for checkOutMeterReading/job");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await ReportItemTransaction.create({
|
||||||
|
type: "PUT",
|
||||||
|
performedOn: item,
|
||||||
|
performedBy: res.locals.user,
|
||||||
|
reportingFor: reportingFor,
|
||||||
|
details: details ? details : "",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
adjustItem: async (req, res, next) => {
|
adjustItem: async (req, res, next) => {
|
||||||
res.status(500).send({ success: false, error: "Not Implemented" });
|
res.status(500).send({ success: false, error: "Not Implemented" });
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const mongoose = require("mongoose");
|
const mongoose = require("mongoose");
|
||||||
const { ItemTransactionTypes } = require("../config/constants");
|
const { ItemTransactionTypes, ReportItemForTypes } = require("../config/constants");
|
||||||
|
|
||||||
const schema = new mongoose.Schema(
|
const schema = new mongoose.Schema(
|
||||||
{
|
{
|
||||||
@@ -111,10 +111,10 @@ const CheckOutItemTransaction = ItemTransaction.discriminator(
|
|||||||
const ReportItemTransaction = ItemTransaction.discriminator(
|
const ReportItemTransaction = ItemTransaction.discriminator(
|
||||||
"Report",
|
"Report",
|
||||||
new mongoose.Schema({
|
new mongoose.Schema({
|
||||||
for: {
|
reportingFor: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
enum: ["LOCATION", "ISSUE", "INCIDENT"]
|
enum: ReportItemForTypes,
|
||||||
},
|
},
|
||||||
details: {
|
details: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user