GWM : draft submission delete api
This commit is contained in:
parent
717b009b9b
commit
850c53c4d6
@ -1130,3 +1130,46 @@ exports.getProductSubmissionHistory = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
exports.deleteDraftSubmissionData = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.query;
|
||||
|
||||
if (!id ) {
|
||||
return res.status(400).json({ status: "failed", message: "Missing required query params" });
|
||||
}
|
||||
|
||||
// find submission
|
||||
const submission = await Submission.findOne({
|
||||
where: { id, status : 'Draft' },
|
||||
});
|
||||
|
||||
if (!submission) {
|
||||
return res.status(404).json({ status: "failed", message: "No submission found for deletion" });
|
||||
}
|
||||
|
||||
// Delete submission products
|
||||
await SubmissionProduct.destroy({
|
||||
where: {
|
||||
submission_id: id,
|
||||
}
|
||||
});
|
||||
|
||||
// Delete submission
|
||||
await Submission.destroy({
|
||||
where: {
|
||||
id,
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return res.status(200).json({ status: "success", data: 'Successfully Deleted' });
|
||||
|
||||
} catch (err) {
|
||||
logger.error(err.message);
|
||||
logger.error(`Stack trace: ${err.stack}`);
|
||||
res.status(500).send({ status: "failed", message: "Internal server error" });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -2508,6 +2508,32 @@ router.get("/submissions/getProductSubmissionHistory",[verifySignature, verifyTo
|
||||
router.get("/submission-audit-history",[verifySignature, verifyToken], submissionController.getSubmissionHistory);
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/submissions/deleteDraftSubmissionData:
|
||||
* get:
|
||||
* summary: Delete submission (hard delete)
|
||||
* tags: [Submissions]
|
||||
* security:
|
||||
* - appSignature: []
|
||||
* - CSRF: []
|
||||
* cookieAuth: [] # or bearerAuth: [] if you use Authorization header
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: id
|
||||
* required: true
|
||||
* schema: { type: integer }
|
||||
* responses:
|
||||
* 200:
|
||||
* description: successfully Deleted
|
||||
* 404:
|
||||
* description: Not found
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.get("/submissions/deleteDraftSubmissionData",[verifySignature, verifyToken], submissionController.deleteDraftSubmissionData);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user