Skip to content

Commit

Permalink
[Added] infrastructre delete route and apidoc for it
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulsingh2312 committed Jul 5, 2023
1 parent a6ed529 commit 455a656
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
12 changes: 12 additions & 0 deletions _apidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@
// ------------------------------------------------------------------------------------------
// History.
// ------------------------------------------------------------------------------------------
/**
* @api {delete} /infrastructure/delete/:documentID Delete Infrastructure
* @apiName DeleteInfrastructure
* @apiGroup Infrastructure
*
* @apiParam {String} documentID The ID of the infrastructure document to delete.
*
* @apiSuccess {String} res Success message indicating the deletion.
*
* @apiError (Error 500) err Error message if there was an error during the deletion.
*
*/
15 changes: 13 additions & 2 deletions controller/infrastructure.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createInfrastructure } from "#services/infrastructure";
import { createInfrastructure, deleteInfrastructure } from "#services/infrastructure";
import { logger } from "#util";

async function addinfrastructure(req, res) {
Expand All @@ -15,4 +15,15 @@ async function addinfrastructure(req, res) {
}
}

export default { addinfrastructure };
async function deleteinfrastructure(req, res) {
const { documentID } = req.params;
try {
await deleteInfrastructure(documentID);

res.json({ res: `Deleted infrastructure with ID ${documentID}` });
} catch (error) {
logger.error("Error while deleting", error);
res.status(500).json({ error: "Error while deleting from DB" });
}
}
export default { addinfrastructure, deleteinfrastructure };
2 changes: 1 addition & 1 deletion models/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ const topicSchema = {
title: { type: String, required: true },
};
// eslint-disable-next-line no-unused-vars
const Topic = connector.model("topic", topicSchema);
const Topic = connector.model("topic", topicSchema);
1 change: 1 addition & 0 deletions routes/infrastructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import infrastructureController from "#controller/infrastructure";

const router = express.Router();
router.post("/add", infrastructureController.addinfrastructure);
router.post("/delete/:documentID", infrastructureController.deleteinfrastructure);

export default router;
9 changes: 9 additions & 0 deletions services/infrastructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ export async function createInfrastructure(name, type, wing, floor, capacity) {
}
throw new databaseError.DataEntryError("infrastructure");
}

export async function deleteInfrastructure(documentID) {
try {
await infrastructure.findOneAndDelete({ _id: documentID });
} catch (error) {
// Handle any errors that occur during the deletion process
throw new Error(`Error deleting infrastructure: ${error.message}`);
}
}

0 comments on commit 455a656

Please sign in to comment.