Added audit field for all create and updae API
This commit is contained in:
parent
c31eabd96f
commit
d7e4d58406
@ -51,7 +51,7 @@ exports.login = async (req, res) => {
|
|||||||
}else{
|
}else{
|
||||||
const establishment_data = await Establishment.findByPk(userData.establishment_id);
|
const establishment_data = await Establishment.findByPk(userData.establishment_id);
|
||||||
tokenData = { id: userData.id, email: userData.email , name: userData.name , role : userRole , establishment_id: userData.establishment_id , establishment_data , last_login : userData.last_login }
|
tokenData = { id: userData.id, email: userData.email , name: userData.name , role : userRole , establishment_id: userData.establishment_id , establishment_data , last_login : userData.last_login }
|
||||||
await EstablishmentUser.update({ last_login : Date() }, { where: { id: userData.id } });
|
await EstablishmentUser.update({ last_login : Date(), updated_by: req.user.id, updated_at: new Date() }, { where: { id: userData.id } });
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = jwt.sign(tokenData, process.env.JWT_SECRET, {
|
const token = jwt.sign(tokenData, process.env.JWT_SECRET, {
|
||||||
|
|||||||
@ -26,7 +26,7 @@ exports.updateDeadlineData = async (req, res) => {
|
|||||||
first_reminder_days_before_deadline,
|
first_reminder_days_before_deadline,
|
||||||
second_reminder_days_before_deadline,
|
second_reminder_days_before_deadline,
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
updated_by,
|
updated_by: req.body.updated_by || req.user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).json({ status: "success", message: "Deadline updated successfully", data: existing });
|
res.status(200).json({ status: "success", message: "Deadline updated successfully", data: existing });
|
||||||
@ -39,7 +39,7 @@ exports.updateDeadlineData = async (req, res) => {
|
|||||||
first_reminder_days_before_deadline,
|
first_reminder_days_before_deadline,
|
||||||
second_reminder_days_before_deadline,
|
second_reminder_days_before_deadline,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
created_by,
|
created_by: req.body.created_by || req.user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(201).json({ status: "success", message: "Deadline created successfully", data: newRecord });
|
res.status(201).json({ status: "success", message: "Deadline created successfully", data: newRecord });
|
||||||
|
|||||||
@ -132,7 +132,7 @@ exports.createEstablishment = async (req, res) => {
|
|||||||
non_emirati_female,
|
non_emirati_female,
|
||||||
total_emirati,
|
total_emirati,
|
||||||
total_employees,
|
total_employees,
|
||||||
created_by,
|
created_by: req.body.created_by || req.user.id,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -145,6 +145,7 @@ exports.createEstablishment = async (req, res) => {
|
|||||||
name: establishment_user.name,
|
name: establishment_user.name,
|
||||||
email: establishment_user.email,
|
email: establishment_user.email,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
|
created_by: req.body.created_by || req.user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
//send email to user
|
//send email to user
|
||||||
@ -513,7 +514,8 @@ exports.updateEstablishment = async (req, res) => {
|
|||||||
return res.status(400).json({ status:"failed", message:"establishment_code already exists" });
|
return res.status(400).json({ status:"failed", message:"establishment_code already exists" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
estData.updated_by = estData.updated_by || req.user.id;
|
||||||
|
estData.updated_at = estData.updated_at || new Date();
|
||||||
// update establishment
|
// update establishment
|
||||||
await establishment.update(estData);
|
await establishment.update(estData);
|
||||||
|
|
||||||
@ -528,6 +530,8 @@ exports.updateEstablishment = async (req, res) => {
|
|||||||
if (establishment_user.password) {
|
if (establishment_user.password) {
|
||||||
updateUser.password = await bcrypt.hash(establishment_user.password,10);
|
updateUser.password = await bcrypt.hash(establishment_user.password,10);
|
||||||
}
|
}
|
||||||
|
updateUser.updated_by = updateUser.updated_by || req.user.id;
|
||||||
|
updateUser.updated_at = updateUser.updated_at || new Date();
|
||||||
await user.update(updateUser);
|
await user.update(updateUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -549,7 +553,7 @@ exports.updateEstablishment = async (req, res) => {
|
|||||||
const newIds = incomingIds.filter(v => !oldIds.includes(v));
|
const newIds = incomingIds.filter(v => !oldIds.includes(v));
|
||||||
|
|
||||||
for (let pid of newIds) {
|
for (let pid of newIds) {
|
||||||
await EstablishmentProduct.create({ establishment_id:id, product_id:pid });
|
await EstablishmentProduct.create({ establishment_id:id, product_id:pid, created_by: req.user.id});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -701,6 +705,7 @@ exports.createRequest = async (req, res) => {
|
|||||||
additional_notes,
|
additional_notes,
|
||||||
establishment_user_id: user.id,
|
establishment_user_id: user.id,
|
||||||
establishment_id: establishment.id,
|
establishment_id: establishment.id,
|
||||||
|
created_by: req.user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trigger Email
|
// Trigger Email
|
||||||
@ -795,13 +800,7 @@ exports.forgotPasswordRequestOTP = async (req, res) => {
|
|||||||
"Password Reset OTP",
|
"Password Reset OTP",
|
||||||
`<p>Dear ${adminUser.name},</p><p>Your OTP for password reset is <b>${otp}</b>. It is valid for 10 minutes.</p>`
|
`<p>Dear ${adminUser.name},</p><p>Your OTP for password reset is <b>${otp}</b>. It is valid for 10 minutes.</p>`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger.info(`OTP sent to ${registered_email}`);
|
logger.info(`OTP sent to ${registered_email}`);
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
@ -1234,8 +1233,6 @@ exports.establishmentBulkUpload = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// exports.establishmentBulkUpload = async (req, res) => {
|
// exports.establishmentBulkUpload = async (req, res) => {
|
||||||
// try {
|
// try {
|
||||||
// // Basic file & user validations
|
// // Basic file & user validations
|
||||||
|
|||||||
@ -5,7 +5,7 @@ const Product = db.Product;
|
|||||||
const UnitMaster = db.UnitMaster;
|
const UnitMaster = db.UnitMaster;
|
||||||
exports.createEstablishmentProduct = async (req, res) => {
|
exports.createEstablishmentProduct = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
req.body.created_by = req.body.created_by || req.user.id;
|
||||||
const data = await EstablishmentProduct.create(req.body);
|
const data = await EstablishmentProduct.create(req.body);
|
||||||
res.status(201).send({'status':"success",'message':"Creation successful",'data': data });
|
res.status(201).send({'status':"success",'message':"Creation successful",'data': data });
|
||||||
|
|
||||||
@ -64,6 +64,9 @@ exports.getEstablishmentProductById = async (req, res) => {
|
|||||||
|
|
||||||
exports.updateEstablishmentProduct = async (req, res) => {
|
exports.updateEstablishmentProduct = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
req.body.updated_by = req.body.updated_by || req.user.id;
|
||||||
|
req.body.updated_at = req.body.updated_at || new Date();
|
||||||
const [updated] = await EstablishmentProduct.update(req.body, { where: { id: req.params.id } });
|
const [updated] = await EstablishmentProduct.update(req.body, { where: { id: req.params.id } });
|
||||||
|
|
||||||
if (!updated) res.status(404).send({'status':"failed",'message':"Record not found",'data': "" });
|
if (!updated) res.status(404).send({'status':"failed",'message':"Record not found",'data': "" });
|
||||||
|
|||||||
@ -23,6 +23,7 @@ exports.createUser = async (req, res) => {
|
|||||||
email,
|
email,
|
||||||
password: hashed,
|
password: hashed,
|
||||||
gender,
|
gender,
|
||||||
|
created_by: req.user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
//send email to user
|
//send email to user
|
||||||
@ -83,6 +84,8 @@ exports.updateUser = async (req, res) => {
|
|||||||
if (email !== undefined && email !== null) data.email = email;
|
if (email !== undefined && email !== null) data.email = email;
|
||||||
if (is_active !== undefined && is_active !== null) data.is_active = is_active;
|
if (is_active !== undefined && is_active !== null) data.is_active = is_active;
|
||||||
if (password && password.trim() !== "") data.password = await bcrypt.hash(password, 10);
|
if (password && password.trim() !== "") data.password = await bcrypt.hash(password, 10);
|
||||||
|
data.updated_by = req.body.updated_by || req.user.id;
|
||||||
|
data.updated_at = req.body.updated_at || new Date();
|
||||||
|
|
||||||
const [updated] = await EstablishmentUser.update(data, {
|
const [updated] = await EstablishmentUser.update(data, {
|
||||||
where: { id: req.params.id },
|
where: { id: req.params.id },
|
||||||
@ -127,7 +130,7 @@ exports.changeUserPassword = async (req, res) => {
|
|||||||
// Hash and update new password
|
// Hash and update new password
|
||||||
const hashedPassword = await bcrypt.hash(new_password, 10);
|
const hashedPassword = await bcrypt.hash(new_password, 10);
|
||||||
await EstablishmentUser.update(
|
await EstablishmentUser.update(
|
||||||
{ password: hashedPassword },
|
{ password: hashedPassword, updated_by: req.user.id, updated_at: new Date() },
|
||||||
{ where: { id: userId } }
|
{ where: { id: userId } }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ const NotificationTemplate = db.NotificationTemplate;
|
|||||||
// Create template
|
// Create template
|
||||||
exports.createTemplate = async (req, res) => {
|
exports.createTemplate = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
req.body.created_by = req.body.created_by || req.user.id;
|
||||||
const template = await NotificationTemplate.create(req.body);
|
const template = await NotificationTemplate.create(req.body);
|
||||||
res.status(201).send({
|
res.status(201).send({
|
||||||
status: "success",
|
status: "success",
|
||||||
@ -51,6 +52,9 @@ exports.getTemplateById = async (req, res) => {
|
|||||||
// Update template
|
// Update template
|
||||||
exports.updateTemplate = async (req, res) => {
|
exports.updateTemplate = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
req.body.updated_by = req.body.updated_by || req.user.id;
|
||||||
|
req.body.updated_at = req.body.updated_at || new Date();
|
||||||
|
|
||||||
const [updated] = await NotificationTemplate.update(req.body, {
|
const [updated] = await NotificationTemplate.update(req.body, {
|
||||||
where: { id: req.params.id },
|
where: { id: req.params.id },
|
||||||
});
|
});
|
||||||
|
|||||||
@ -84,7 +84,8 @@ exports.updateProduct = async (req, res) => {
|
|||||||
|
|
||||||
const object = {
|
const object = {
|
||||||
...req.body,
|
...req.body,
|
||||||
updated_at: Sequelize.literal("NOW()")
|
updated_by: req.user.id,
|
||||||
|
updated_at: new Date()
|
||||||
};
|
};
|
||||||
|
|
||||||
const [updated] = await Product.update(object, { where: { id: req.params.id } });
|
const [updated] = await Product.update(object, { where: { id: req.params.id } });
|
||||||
|
|||||||
@ -26,6 +26,7 @@ exports.createConfig = async (req, res) => {
|
|||||||
req.body.assigned = assignedCount;
|
req.body.assigned = assignedCount;
|
||||||
req.body.responded = 0;
|
req.body.responded = 0;
|
||||||
req.body.not_responded = assignedCount;
|
req.body.not_responded = assignedCount;
|
||||||
|
req.body.created_by = req.body.created_by || req.user.id;
|
||||||
|
|
||||||
const data = await QuarterlyWindowsConfiguration.create(req.body);
|
const data = await QuarterlyWindowsConfiguration.create(req.body);
|
||||||
res.status(201).send({
|
res.status(201).send({
|
||||||
@ -83,6 +84,8 @@ exports.getConfigById = async (req, res) => {
|
|||||||
// Update configuration
|
// Update configuration
|
||||||
exports.updateConfig = async (req, res) => {
|
exports.updateConfig = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
req.body.updated_by = req.body.updated_by || req.user.id;
|
||||||
|
req.body.updated_at = req.body.updated_at || new Date();
|
||||||
const [updated] = await QuarterlyWindowsConfiguration.update(req.body, {
|
const [updated] = await QuarterlyWindowsConfiguration.update(req.body, {
|
||||||
where: { id: req.params.id },
|
where: { id: req.params.id },
|
||||||
});
|
});
|
||||||
|
|||||||
@ -35,7 +35,7 @@ exports.createSubmission = async (req, res) => {
|
|||||||
if (exists) {
|
if (exists) {
|
||||||
return res.status(400).json({status: "failed", message: `Submission already exists for establishment_id: ${establishment_id}, quarter: ${quarter}, year: ${year}`});
|
return res.status(400).json({status: "failed", message: `Submission already exists for establishment_id: ${establishment_id}, quarter: ${quarter}, year: ${year}`});
|
||||||
}
|
}
|
||||||
|
submissionData.created_by = submissionData.created_by || req.user.id;
|
||||||
|
|
||||||
const submission = await Submission.create({establishment_id, quarter, year, ...submissionData});
|
const submission = await Submission.create({establishment_id, quarter, year, ...submissionData});
|
||||||
|
|
||||||
@ -45,12 +45,9 @@ exports.createSubmission = async (req, res) => {
|
|||||||
const currentResponded = config.responded ?? 0;
|
const currentResponded = config.responded ?? 0;
|
||||||
const currentNotResponded = config.not_responded ?? 0;
|
const currentNotResponded = config.not_responded ?? 0;
|
||||||
// respond increase, not responded decrease
|
// respond increase, not responded decrease
|
||||||
await QuarterlyWindowsConfiguration.update({responded: currentResponded + 1, not_responded: currentNotResponded - 1 }, {where: { id: config.id }} );
|
await QuarterlyWindowsConfiguration.update({responded: currentResponded + 1, not_responded: currentNotResponded - 1, updated_by: req.user.id, updated_at: new Date() }, {where: { id: config.id }} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (products.length) {
|
if (products.length) {
|
||||||
// products.forEach((p) => (p.submission_id = submission.id));
|
// products.forEach((p) => (p.submission_id = submission.id));
|
||||||
// await SubmissionProduct.bulkCreate(products);
|
// await SubmissionProduct.bulkCreate(products);
|
||||||
@ -212,6 +209,9 @@ exports.updateSubmission = async (req, res) => {
|
|||||||
if (!submission)
|
if (!submission)
|
||||||
return res.status(404).json({ status: "failed", message: "Submission not found" });
|
return res.status(404).json({ status: "failed", message: "Submission not found" });
|
||||||
|
|
||||||
|
submissionData.updated_by = submissionData.updated_by || req.user.id;
|
||||||
|
submissionData.updated_at = submissionData.updated_at || new Date();
|
||||||
|
|
||||||
// Update main submission record
|
// Update main submission record
|
||||||
await submission.update(submissionData);
|
await submission.update(submissionData);
|
||||||
|
|
||||||
@ -270,11 +270,15 @@ exports.updateSubmission = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (existingProduct) {
|
if (existingProduct) {
|
||||||
|
updatedProductData.updated_by = updatedProductData.updated_by || req.user.id;
|
||||||
|
updatedProductData.updated_at = updatedProductData.updated_at || new Date();
|
||||||
await existingProduct.update(updatedProductData);
|
await existingProduct.update(updatedProductData);
|
||||||
} else {
|
} else {
|
||||||
|
updatedProductData.created_by = updatedProductData.created_by || req.user.id;
|
||||||
await SubmissionProduct.create(updatedProductData);
|
await SubmissionProduct.create(updatedProductData);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
updatedProductData.created_by = updatedProductData.created_by || req.user.id;
|
||||||
await SubmissionProduct.create(updatedProductData);
|
await SubmissionProduct.create(updatedProductData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -675,7 +679,7 @@ exports.submissionEditRequest = async (req, res) => {
|
|||||||
return res.status(404).json({ status: "failed", message: "Submission not found" });
|
return res.status(404).json({ status: "failed", message: "Submission not found" });
|
||||||
|
|
||||||
// Update submission main data
|
// Update submission main data
|
||||||
await submission.update({ edit_request });
|
await submission.update({ edit_request, updated_by: req.user.id, updated_at: new Date() });
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
status: "success",
|
status: "success",
|
||||||
@ -701,7 +705,7 @@ exports.enableOrDisableSubmissionEditAccess = async (req, res) => {
|
|||||||
return res.status(404).json({ status: "failed", message: "Submission not found" });
|
return res.status(404).json({ status: "failed", message: "Submission not found" });
|
||||||
|
|
||||||
// Update submission main data
|
// Update submission main data
|
||||||
const result = await submission.update({ edit_request : 0 , edit_access : edit_access});
|
const result = await submission.update({ edit_request : 0 , edit_access : edit_access, updated_by: req.user.id, updated_at: new Date()});
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
status: "success",
|
status: "success",
|
||||||
@ -736,7 +740,7 @@ exports.approveOrRejectSubmission = async (req, res) => {
|
|||||||
return res.status(404).json({ status: "failed", message: "Submission not found" });
|
return res.status(404).json({ status: "failed", message: "Submission not found" });
|
||||||
|
|
||||||
// Update submission main data
|
// Update submission main data
|
||||||
const result = await submission.update({ approve_reject_status : approve_reject_status , status : statusString, reject_reason, approve_or_reject_by });
|
const result = await submission.update({ approve_reject_status : approve_reject_status , status : statusString, reject_reason, approve_or_reject_by, updated_by: req.user.id, updated_at: new Date() });
|
||||||
|
|
||||||
|
|
||||||
//send email to establishment user
|
//send email to establishment user
|
||||||
|
|||||||
@ -89,6 +89,7 @@ exports.createUnit = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
req.body.uom_short_name = uomShort;
|
req.body.uom_short_name = uomShort;
|
||||||
|
req.body.created_by = req.body.created_by || req.user.id;
|
||||||
|
|
||||||
const unit = await UnitMaster.create(req.body);
|
const unit = await UnitMaster.create(req.body);
|
||||||
res.status(201).json({ status: "success", data: unit });
|
res.status(201).json({ status: "success", data: unit });
|
||||||
@ -137,6 +138,9 @@ exports.updateUnit = async (req, res) => {
|
|||||||
const unit = await UnitMaster.findByPk(req.params.id);
|
const unit = await UnitMaster.findByPk(req.params.id);
|
||||||
if (!unit) return res.status(404).json({ status: "error", message: "Unit not found" });
|
if (!unit) return res.status(404).json({ status: "error", message: "Unit not found" });
|
||||||
|
|
||||||
|
req.body.updated_by = req.body.updated_by || req.user.id;
|
||||||
|
req.body.updated_at = req.body.updated_at || new Date();
|
||||||
|
|
||||||
await unit.update(req.body);
|
await unit.update(req.body);
|
||||||
res.status(200).json({ status: "success", data: unit });
|
res.status(200).json({ status: "success", data: unit });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ exports.createReason = async (req, res) => {
|
|||||||
if (!reason)
|
if (!reason)
|
||||||
return res.status(400).send({ status: "failed", message: "Reason is required" });
|
return res.status(400).send({ status: "failed", message: "Reason is required" });
|
||||||
|
|
||||||
const newReason = await VariationReasonMaster.create({ reason, high_or_low });
|
const newReason = await VariationReasonMaster.create({ reason, high_or_low, created_by: req.body.created_by || req.user.id });
|
||||||
res.status(201).send({ status: "success", message: "Reason created successfully", data: newReason });
|
res.status(201).send({ status: "success", message: "Reason created successfully", data: newReason });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(500).send({ status: "failed", message: err.message });
|
res.status(500).send({ status: "failed", message: err.message });
|
||||||
@ -43,7 +43,7 @@ exports.updateReason = async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const { reason, high_or_low, is_active } = req.body;
|
const { reason, high_or_low, is_active } = req.body;
|
||||||
const updated = await VariationReasonMaster.update(
|
const updated = await VariationReasonMaster.update(
|
||||||
{ reason, high_or_low, is_active, updated_at: new Date(), updated_on: new Date() },
|
{ reason, high_or_low, is_active, updated_at: new Date(), updated_on: new Date(), updated_by: req.user.id },
|
||||||
{ where: { id: req.params.id } }
|
{ where: { id: req.params.id } }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -1,20 +1,20 @@
|
|||||||
const db = require("../models");
|
const db = require("../models");
|
||||||
const ZeroTargetReasonMaster = db.ZeroTargetReasonMaster;
|
const ZeroTargetReasonMaster = db.ZeroTargetReasonMaster;
|
||||||
|
|
||||||
// ✅ Create
|
// Create
|
||||||
exports.create = async (req, res) => {
|
exports.create = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { reason, is_active } = req.body;
|
const { reason, is_active } = req.body;
|
||||||
if (!reason) return res.status(400).send({ status: "failed", message: "Reason is required" });
|
if (!reason) return res.status(400).send({ status: "failed", message: "Reason is required" });
|
||||||
|
|
||||||
const data = await ZeroTargetReasonMaster.create({ reason, is_active });
|
const data = await ZeroTargetReasonMaster.create({ reason, is_active, created_by: req.user.id });
|
||||||
res.status(201).send({ status: "success", data });
|
res.status(201).send({ status: "success", data });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(500).send({ status: "failed", message: err.message });
|
res.status(500).send({ status: "failed", message: err.message });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ✅ Get All
|
// Get All
|
||||||
exports.getAll = async (req, res) => {
|
exports.getAll = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const data = await ZeroTargetReasonMaster.findAll();
|
const data = await ZeroTargetReasonMaster.findAll();
|
||||||
@ -24,7 +24,7 @@ exports.getAll = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ✅ Get By ID
|
// Get By ID
|
||||||
exports.getById = async (req, res) => {
|
exports.getById = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
@ -36,10 +36,12 @@ exports.getById = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ✅ Update
|
// Update
|
||||||
exports.update = async (req, res) => {
|
exports.update = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
req.body.updated_by = req.body.updated_by || req.user.id;
|
||||||
|
req.body.updated_at = req.body.updated_at || new Date();
|
||||||
const [updated] = await ZeroTargetReasonMaster.update(req.body, { where: { id } });
|
const [updated] = await ZeroTargetReasonMaster.update(req.body, { where: { id } });
|
||||||
if (!updated) return res.status(404).send({ status: "failed", message: "Not found" });
|
if (!updated) return res.status(404).send({ status: "failed", message: "Not found" });
|
||||||
const data = await ZeroTargetReasonMaster.findByPk(id);
|
const data = await ZeroTargetReasonMaster.findByPk(id);
|
||||||
@ -49,7 +51,7 @@ exports.update = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ✅ Delete
|
// Delete
|
||||||
exports.delete = async (req, res) => {
|
exports.delete = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
|||||||
@ -38,7 +38,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
created_by: {
|
created_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: true,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
updated_by: {
|
updated_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
@ -48,8 +48,14 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
{
|
{
|
||||||
tableName: "unit_master",
|
tableName: "unit_master",
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
createdAt: "created_at",
|
createdAt: {
|
||||||
updatedAt: "updated_at",
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW,
|
||||||
|
},
|
||||||
|
updatedAt: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
defaultValue: DataTypes.NOW,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -61,7 +61,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
created_by: {
|
created_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: true,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
updated_at: {
|
updated_at: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
|
|||||||
@ -15,7 +15,8 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
created_at: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
|
created_at: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
|
||||||
updated_at: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
|
updated_at: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
|
||||||
updated_by: { type: DataTypes.INTEGER },
|
created_by: {type: DataTypes.INTEGER, allowNull: false },
|
||||||
|
updated_by: { type: DataTypes.INTEGER, allowNull: true },
|
||||||
establishment_user_id: { type: DataTypes.INTEGER },
|
establishment_user_id: { type: DataTypes.INTEGER },
|
||||||
establishment_id: { type: DataTypes.INTEGER },
|
establishment_id: { type: DataTypes.INTEGER },
|
||||||
},
|
},
|
||||||
|
|||||||
@ -23,7 +23,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
created_by: {
|
created_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: true,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
updated_at: {
|
updated_at: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
|
|||||||
@ -38,7 +38,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
created_by: {
|
created_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: true,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
updated_at: {
|
updated_at: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
|
|||||||
@ -40,6 +40,8 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
|
created_by: {type: DataTypes.INTEGER, allowNull: false },
|
||||||
|
updated_by: { type: DataTypes.INTEGER, allowNull: true },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tableName: "notification_templates",
|
tableName: "notification_templates",
|
||||||
|
|||||||
@ -31,7 +31,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
created_by: {
|
created_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: true,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
updated_at: {
|
updated_at: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
|
|||||||
@ -41,7 +41,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
created_by: {
|
created_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: true,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
updated_at: {
|
updated_at: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
|
|||||||
@ -45,7 +45,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
created_by: {
|
created_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: true,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
updated_by: {
|
updated_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
|
|||||||
@ -33,7 +33,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
created_by: {
|
created_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: true,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
updated_by: {
|
updated_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
|
|||||||
@ -28,13 +28,21 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
updated_by: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
created_at: {
|
created_at: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
|
},
|
||||||
|
created_by: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
updated_at: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
updated_by: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -51,8 +51,14 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
zero_target_reason_master_id: DataTypes.INTEGER,
|
zero_target_reason_master_id: DataTypes.INTEGER,
|
||||||
other_zero_target_reason: DataTypes.STRING(255),
|
other_zero_target_reason: DataTypes.STRING(255),
|
||||||
remarks: DataTypes.STRING(255),
|
remarks: DataTypes.STRING(255),
|
||||||
created_by: DataTypes.INTEGER,
|
created_by: {
|
||||||
updated_by: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
updated_by: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
is_active: {
|
is_active: {
|
||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
|
|||||||
@ -24,7 +24,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
created_by: {
|
created_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: true,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
updated_at: {
|
updated_at: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
|
|||||||
@ -19,7 +19,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
created_by: {
|
created_by: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: true,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
updated_at: {
|
updated_at: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user