diff --git a/controller/accreditation.js b/controller/accreditation.js index c5f6741..b3a5209 100644 --- a/controller/accreditation.js +++ b/controller/accreditation.js @@ -16,10 +16,9 @@ async function addAccreditation(req, res) { } } async function deleteAccreditation(req, res) { - const { filter } = req.params; - console.log(filter) + const { accredationId} = req.params; try { - await deleteAccreditationById(filter); + await deleteAccreditationById(accredationId); res.json({ res: "Accreditation deleted successfully" }); } catch (error) { logger.error("Error while deleting", error); diff --git a/routes/accreditation.js b/routes/accreditation.js index cce87e9..94e72c4 100644 --- a/routes/accreditation.js +++ b/routes/accreditation.js @@ -3,5 +3,5 @@ import accreditationController from "#controller/accreditation"; const router = express.Router(); router.post("/add", accreditationController.addAccreditation); -router.delete("/delete/:filter", accreditationController.deleteAccreditation); -export default router; \ No newline at end of file +router.delete("/delete/:accredationId", accreditationController.deleteAccreditation); +export default router; diff --git a/services/accreditation.js b/services/accreditation.js index 4d73e8b..51c8664 100644 --- a/services/accreditation.js +++ b/services/accreditation.js @@ -1,8 +1,5 @@ import accreditation from "#models/accreditation"; import databaseError from "#error/database"; -import { logger } from "#util"; -import database from "#error/database"; -import router from "#routes/index"; export async function addNewAccreditation(name, agencyName, dateofAccreditation, dateofExpiry) { const newAccreditation = await accreditation.create( @@ -17,10 +14,13 @@ export async function addNewAccreditation(name, agencyName, dateofAccreditation, throw new databaseError.DataEntryError("Accreditation"); } -export async function deleteAccreditationById(accreditationID){ - const result = await router.delete('/accreditations/:accreditationID', (req, res) => { - const { accreditationID } = req.params; - });} +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 } \ No newline at end of file