Skip to content

Commit

Permalink
Merge pull request #181 from avidavatar/121-Create_delete_endpoint_fo…
Browse files Browse the repository at this point in the history
…r_accreditation

121 create delete endpoint for accreditation
  • Loading branch information
Hitansh159 authored Jul 8, 2023
2 parents 2d7fe1c + 41f502c commit 87698a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
16 changes: 13 additions & 3 deletions controller/accreditation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addNewAccreditation } from "#services/accreditation";
import { addNewAccreditation, deleteAccreditationById } from "#services/accreditation";
import { logger } from "#util";

async function addAccreditation(req, res) {
Expand All @@ -15,5 +15,15 @@ async function addAccreditation(req, res) {
res.json({ err: "Error while inserting in DB" });
}
}

export default { addAccreditation };
async function deleteAccreditation(req, res) {
const { accredationId} = req.params;
try {
await deleteAccreditationById(accredationId);
res.json({ res: "Accreditation deleted successfully" });
} catch (error) {
logger.error("Error while deleting", error);
res.status(500);
res.json({ err: "Error while deleting from DB" });
}
}
export default { addAccreditation, deleteAccreditation };
1 change: 1 addition & 0 deletions routes/accreditation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import accreditationController from "#controller/accreditation";

const router = express.Router();
router.post("/add", accreditationController.addAccreditation);
router.delete("/delete/:accredationId", accreditationController.deleteAccreditation);
export default router;
11 changes: 11 additions & 0 deletions services/accreditation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ export async function addNewAccreditation(name, agencyName, dateofAccreditation,
}
throw new databaseError.DataEntryError("Accreditation");
}

export async function deleteAccreditationById(accredationId){
const deleted = await accreditation.remove({_id: accredationId});
if (deleted) {
return deleted
}
throw new databaseError.DataDeleteError("Accreditation");
}
export default {
deleteAccreditationById, addNewAccreditation
}

0 comments on commit 87698a3

Please sign in to comment.