Skip to content

Commit

Permalink
🔥 feat: Implement updating a captain rank (type)
Browse files Browse the repository at this point in the history
  • Loading branch information
akramhany committed Dec 25, 2023
1 parent 6b8ea9f commit eb3a51b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions server/controllers/captain.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,36 @@ const captainController = {
})
}
},
setCaptainType: async (req, res) => {
try {
const { captainId } = req.params
const { type } = req.body

//if (type != 'regular' && type != 'unit' && type != 'general') {
//
//}

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

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

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

export default captainController
1 change: 1 addition & 0 deletions server/routes/captain.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ captainRouter.get(
'/sector/:baseName/:suffixName',
captainController.getCaptainsInSector
)
captainRouter.patch('/type/change/:captainId', captainController.setCaptainType)

export default captainRouter

0 comments on commit eb3a51b

Please sign in to comment.