Skip to content

Commit

Permalink
added service function
Browse files Browse the repository at this point in the history
  • Loading branch information
hricha11 committed Jul 6, 2023
1 parent 2baed66 commit 41f502c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
5 changes: 2 additions & 3 deletions controller/accreditation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions routes/accreditation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
router.delete("/delete/:accredationId", accreditationController.deleteAccreditation);
export default router;
14 changes: 7 additions & 7 deletions services/accreditation.js
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
}

0 comments on commit 41f502c

Please sign in to comment.