Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

121 create delete endpoint for accreditation #181

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading