Skip to content

Commit

Permalink
🎨 refactor: Make the ids in captain descriptive
Browse files Browse the repository at this point in the history
  • Loading branch information
akramhany committed Dec 27, 2023
1 parent 11ad7de commit f26fa83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions server/controllers/captain.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ const captainController = {
getCaptain: async (req, res) => {
try {
// Extract the captain ID from the request params
const { id } = req.params
const { captainId } = req.params

// Query on the database to get that captain info
const result = await db.query(
`SELECT *
FROM "Captain"
WHERE "captainId" = $1`,
[id]
[captainId]
)

// If captain doesn't exist return an error message
Expand Down Expand Up @@ -124,10 +124,10 @@ const captainController = {
// @access Private
setCaptainType: async (req, res) => {
try {
const { id } = req.params
const { captainId } = req.params
const { type } = req.body

if (!id) {
if (!captainId) {
return res.status(400).json({
error: "Please enter a valid id",
})
Expand All @@ -146,7 +146,7 @@ const captainController = {
WHERE "captainId" = $1
RETURNING *
`,
[id, type])
[captainId, type])

res.status(200).json({
message: "Successful update",
Expand Down
4 changes: 2 additions & 2 deletions server/routes/captain.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ captainRouter.get(
'/sector/:baseName/:suffixName',
captainController.getCaptainsInSector
)
captainRouter.get('/:id', captainController.getCaptain)
captainRouter.patch('/:id', captainController.setCaptainType)
captainRouter.get('/:captainId', captainController.getCaptain)
captainRouter.patch('/:captainId', captainController.setCaptainType)

export default captainRouter

0 comments on commit f26fa83

Please sign in to comment.