Skip to content

Commit

Permalink
✨ feat: Implement inserting a new sector
Browse files Browse the repository at this point in the history
  • Loading branch information
akramhany committed Dec 25, 2023
1 parent b5a9a9b commit 6b8ea9f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions server/controllers/sector.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ const sectorController = {
})
}
},
// @desc Insert a new sector given its baseName, suffixName and unitCaptainId(optional)
// @route POST /api/sector/add
// @access Private
insertSector: async (req, res) => {
try {
const { baseName, suffixName, unitCaptainId } = req.body

const result = await db.query(`
INSERT INTO "Sector" VALUES ($1, $2, $3)
RETURNING *
`,
[baseName, suffixName, unitCaptainId])

res.status(200).json({
message: "Successful insertion",
body: result.rows,
})

} catch (error) {
console.log(error)
res.status(500).json({
error: 'An error occured while retrieving the captains info',
body: error,
})
}
},
}

export default sectorController;
1 change: 1 addition & 0 deletions server/routes/sector.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const sectorRouter = Router();

sectorRouter.get('/all', sectorController.getAllSectors)
sectorRouter.get('/:baseName/:suffixName', sectorController.getSector)
sectorRouter.post('/add', sectorController.insertSector)


export default sectorRouter;

0 comments on commit 6b8ea9f

Please sign in to comment.