Skip to content

Commit

Permalink
Merge pull request #42 from CMP26Projects/backend-functionalities
Browse files Browse the repository at this point in the history
✨ feat: Implement assigning a regular captain to a sector
  • Loading branch information
amir-kedis authored Dec 27, 2023
2 parents 44a40e1 + d3ca521 commit 5b8258a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions server/controllers/sector.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,39 @@ const sectorController = {
})
}
},
assignCaptain: async (req, res) => {
try {
const { baseName, suffixName } = req.params
const { captainId } = req.body

const result = await db.query(`
UPDATE "Captain"
SET "rSectorBaseName" = $1, "rSectorSuffixName" = $2
WHERE "captainId" = $3
RETURNING *
`,
[baseName, suffixName, captainId])

if (result.rowCount === 0) {
return res.status(400).json({
error: "Error occured while assigning captain"
})
}

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

} catch (error) {
console.log(error)
res.status(500).json({
error: 'An error occured while assigning a regular captain to a sector',
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 @@ -12,5 +12,6 @@ sectorRouter.patch(
//TODO: Check if the captain id is for a unit captain
sectorController.setUnitCaptain
)
sectorRouter.patch('/captain/:baseName/:suffixName', sectorController.assignCaptain)

export default sectorRouter

0 comments on commit 5b8258a

Please sign in to comment.