From 8c3995747daf8649bbd7c9dddd3b759809e821f2 Mon Sep 17 00:00:00 2001 From: mustafahincal Date: Fri, 21 Jun 2024 15:49:11 +0300 Subject: [PATCH] feat: update process for discontinuity --- v1/src/controllers/rpDiscs.controller.js | 12 ++++++++++++ v1/src/routes/rpDiscs.routes.js | 2 ++ v1/src/services/rpDisc.service.js | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/v1/src/controllers/rpDiscs.controller.js b/v1/src/controllers/rpDiscs.controller.js index ec0f787..346103c 100644 --- a/v1/src/controllers/rpDiscs.controller.js +++ b/v1/src/controllers/rpDiscs.controller.js @@ -2,6 +2,7 @@ const { listDiscs, getDiscsByRpId, insertDisc, + updateDisc, bulkDeleteRpDiscs, bulkInsertDisc, } = require('../services/rpDisc.service'); @@ -31,6 +32,16 @@ const create = async (req, res) => { }); }; +const update = async (req, res) => { + const { discId } = req.params; + const disc = await updateDisc(discId, req.body); + res.send({ + disc, + success: true, + message: 'Disc updated successfully', + }); +}; + const bulkDelete = async (req, res) => { await bulkDeleteRpDiscs(req.body); res.send({ @@ -52,6 +63,7 @@ module.exports = { index, listByRpId, create, + update, bulkDelete, manual, }; diff --git a/v1/src/routes/rpDiscs.routes.js b/v1/src/routes/rpDiscs.routes.js index 9907604..b7382f8 100644 --- a/v1/src/routes/rpDiscs.routes.js +++ b/v1/src/routes/rpDiscs.routes.js @@ -3,6 +3,7 @@ const { index, listByRpId, create, + update, bulkDelete, manual, } = require('../controllers/rpDiscs.controller'); @@ -12,6 +13,7 @@ const router = express.Router(); router.route('/').get(errorCatcher(index)); router.route('/').post(errorCatcher(create)); +router.route('/:discId').put(errorCatcher(update)); router.route('/:id').get(errorCatcher(listByRpId)); router.route('/bulk-delete').post(errorCatcher(bulkDelete)); router.route('/manual').post(errorCatcher(manual)); diff --git a/v1/src/services/rpDisc.service.js b/v1/src/services/rpDisc.service.js index e558f42..a90cdb7 100644 --- a/v1/src/services/rpDisc.service.js +++ b/v1/src/services/rpDisc.service.js @@ -6,6 +6,12 @@ const insert = async (discData) => { throw new Error('Disc not created'); }; +const update = async (discId, discData) => { + const disc = await RPDisc.findByIdAndUpdate(discId, discData, { new: true }); + if (disc) return disc; + throw new Error('Disc not updated'); +}; + const insertDiscs = async (discsData) => { const discs = await RPDisc.insertMany(discsData); if (discs) return discs; @@ -35,6 +41,7 @@ const bulkInsertDisc = async (discs) => { module.exports = { insertDisc: insert, insertDiscs: insertDiscs, + updateDisc: update, listDiscs: list, getDiscsByRpId, bulkDeleteRpDiscs,