Skip to content

Commit

Permalink
✨ feat: Make getAllCaptains accept the type of captains to get
Browse files Browse the repository at this point in the history
  • Loading branch information
akramhany committed Dec 26, 2023
1 parent dd4bad6 commit e1d3358
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions server/controllers/captain.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@ import db from '../database/db.js'
const captainController = {
getAllCaptains: async (req, res) => {
try {
// Query on the database to get the captains info
const result = await db.query(`SELECT * FROM "Captain"`)
const { type } = req.body

let result;
if (type === 'regular') {
result = await db.query(`SELECT * FROM "Captain" WHERE "type" = 'regular'`)
}
else if (type === 'unit') {
result = await db.query(`SELECT * FROM "Captain" WHERE "type" = 'unit'`)
}
else if (type === 'general') {
result = await db.query(`SELECT * FROM "Captain" WHERE "type" = 'general'`)
}
else {
result = await db.query(`SELECT * FROM "Captain"`)
}

// Respond with the data retrieved and a successful retrieval message
res.status(200).json({
Expand Down

0 comments on commit e1d3358

Please sign in to comment.