diff --git a/controller/infrastructure.js b/controller/infrastructure.js index f49f27f..6b426ae 100644 --- a/controller/infrastructure.js +++ b/controller/infrastructure.js @@ -1,4 +1,5 @@ -import { createInfrastructure } from "#services/infrastructure"; +import infrastructure from "#models/infrastructure"; +import { createInfrastructure, updateinfrastructure } from "#services/infrastructure"; import { logger } from "#util"; async function addinfrastructure(req, res) { @@ -15,4 +16,17 @@ async function addinfrastructure(req, res) { } } -export default { addinfrastructure }; +async function updateinfrastructure(req,res){ + const{ + name , type, wing, floor, capacity + }= req.body; + try{ + const updateinfrastructure=await updateinfrastructure(filter,data); + res.json({res: `updated infrastructure ${updateinfrastructure.id}`}); + }catch(error){ + logger.error("Error while updating",error); + res.status(500); + res.json({err:"Error while updaing in DB"}); + } + } +export default { addinfrastructure,updateinfrastructure }; diff --git a/routes/infrastructure.js b/routes/infrastructure.js index 84c9e38..8ab1f5a 100644 --- a/routes/infrastructure.js +++ b/routes/infrastructure.js @@ -2,6 +2,6 @@ import express from "express"; import infrastructureController from "#controller/infrastructure"; const router = express.Router(); -router.post("/add", infrastructureController.addinfrastructure); - +router.post("/add",infrastructureController.addinfrastructure) +router.post("/update",infrastructureController.updateinfrastructure); export default router; diff --git a/services/infrastructure.js b/services/infrastructure.js index 4e8247b..a76b2d5 100644 --- a/services/infrastructure.js +++ b/services/infrastructure.js @@ -10,3 +10,12 @@ export async function createInfrastructure(name, type, wing, floor, capacity) { } throw new databaseError.DataEntryError("infrastructure"); } + +export async function updateinfrastructure(filter,data){ + const updateInfrastructure = await infrastructure.update({filter,data + }); + if(updateInfrastructure.name === name){ + return updateInfrastructure; + } +throw new databaseError.DataEntryError("Infrastructure"); +} \ No newline at end of file