From 850c53c4d647e89447fb02efaf1bee1bdee2b35c Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 4 Feb 2026 17:05:22 +0530 Subject: [PATCH] GWM : draft submission delete api --- app/controllers/submission.controller.js | 43 ++++++++++++++++++++++++ app/routes/routes.js | 26 ++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/app/controllers/submission.controller.js b/app/controllers/submission.controller.js index 932aabc..7e38802 100644 --- a/app/controllers/submission.controller.js +++ b/app/controllers/submission.controller.js @@ -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" }); + } +}; + diff --git a/app/routes/routes.js b/app/routes/routes.js index 9a99e6f..a133fca 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -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); + +