Skip to content

Commit

Permalink
feat: update process for discontinuity
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafahincal committed Jun 21, 2024
1 parent 0cb1161 commit 8c39957
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions v1/src/controllers/rpDiscs.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {
listDiscs,
getDiscsByRpId,
insertDisc,
updateDisc,
bulkDeleteRpDiscs,
bulkInsertDisc,
} = require('../services/rpDisc.service');
Expand Down Expand Up @@ -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({
Expand All @@ -52,6 +63,7 @@ module.exports = {
index,
listByRpId,
create,
update,
bulkDelete,
manual,
};
2 changes: 2 additions & 0 deletions v1/src/routes/rpDiscs.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
index,
listByRpId,
create,
update,
bulkDelete,
manual,
} = require('../controllers/rpDiscs.controller');
Expand All @@ -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));
Expand Down
7 changes: 7 additions & 0 deletions v1/src/services/rpDisc.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,6 +41,7 @@ const bulkInsertDisc = async (discs) => {
module.exports = {
insertDisc: insert,
insertDiscs: insertDiscs,
updateDisc: update,
listDiscs: list,
getDiscsByRpId,
bulkDeleteRpDiscs,
Expand Down

0 comments on commit 8c39957

Please sign in to comment.