Skip to content

Commit

Permalink
Created updated endpoint for infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
deepti-50 committed Jul 6, 2023
1 parent a6ed529 commit 2a99c1a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
18 changes: 16 additions & 2 deletions controller/infrastructure.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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 };
4 changes: 2 additions & 2 deletions routes/infrastructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 updateinfrastructure(filter,data){
const updateInfrastructure = await infrastructure.update({filter,data
});
if(updateInfrastructure.name === name){
return updateInfrastructure;
}
throw new databaseError.DataEntryError("Infrastructure");
}

0 comments on commit 2a99c1a

Please sign in to comment.