diff --git a/server/src/controllers/accounts.controllers.ts b/server/src/controllers/accounts.controllers.ts index c5de8e127b271914323053700eca13c93ea0cd7f..451169224c7d0f5fba6e1aace0383a34b8a30d42 100644 --- a/server/src/controllers/accounts.controllers.ts +++ b/server/src/controllers/accounts.controllers.ts @@ -56,7 +56,18 @@ const showAllAccounts = async (req: Request, res: Response) => { .json({ success: false, error: "MustBeCoordinator" }); } const allAccounts = await Employee.findAll(); - return res.status(200).send({ success: true, result: allAccounts }); + return res.status(200).send({ + success: true, + result: allAccounts.map((account) => { + return { + id: account.id, + first_name: account.first_name, + last_name: account.last_name, + email: account.email, + role: account.role, + }; + }), + }); } catch (error) { console.error("server error: ", error.message); return res.status(500).json({ success: false, error: "serverError" }); @@ -74,7 +85,16 @@ const showAccountById = async (req: Request, res: Response) => { const givenId = req.params.id; const account = await Employee.findByPk(givenId); if (account) { - return res.status(200).json({ success: true, result: account }); + return res.status(200).json({ + success: true, + result: { + id: account.id, + first_name: account.first_name, + last_name: account.last_name, + email: account.email, + role: account.role, + }, + }); } return res.status(404).json({ success: false, error: "accountIdNotFound" }); } catch (error) { @@ -121,7 +141,16 @@ const updateAccount = async (req: Request, res: Response) => { const userData = userDataAfterUpdate[1][0]; delete userData.password; - return res.status(200).json({ success: true, result: userData }); + return res.status(200).json({ + success: true, + result: { + id: userData.id, + first_name: userData.first_name, + last_name: userData.last_name, + email: userData.email, + role: userData.role, + }, + }); } catch (error) { console.error("server error: ", error.message); return res.status(500).json({ success: false, error: "serverError" }); diff --git a/server/src/controllers/boatControllers.controllers.ts b/server/src/controllers/boatControllers.controllers.ts index 852337d1dd48b8d0ed71ca36bab0288e42410e69..3c5211f1d3dcf91248c668bc1e8ae1bbf1e5c582 100644 --- a/server/src/controllers/boatControllers.controllers.ts +++ b/server/src/controllers/boatControllers.controllers.ts @@ -14,15 +14,25 @@ const createBoat = async (req: Request, res: Response) => { const newBoatInput = req.body; const boatType = await BoatType.findByPk(newBoatInput.boattype); - if(!boatType){ - return res.status(404).json({success: false, error: "boattypeNotFound"}) + if (!boatType) { + return res + .status(404) + .json({ success: false, error: "boattypeNotFound" }); } const newBoat = await Boat.create(newBoatInput); if (newBoat) { - return res - .status(201) - .json({ success: true, result: newBoat }); + return res.status(201).json({ + success: true, + result: { + id: newBoat.id, + name: newBoat.name, + boatTypeId: newBoat.boattype, + status: newBoat.status, + active: newBoat.active, + tags: newBoat.tags, + }, + }); } } catch (error) { console.error(error.message); @@ -30,12 +40,23 @@ const createBoat = async (req: Request, res: Response) => { } }; - //show all boats const showAllBoatsController = async (req: Request, res: Response) => { try { const allBoats = await Boat.findAll(); - return res.status(200).send({ success: true, result: allBoats }); + return res.status(200).send({ + success: true, + result: allBoats.map((boat) => { + return { + id: boat.id, + name: boat.name, + boatType: boat.boattype, + status: boat.status, + active: boat.active, + tags: boat.tags, + }; + }), + }); } catch (error) { console.error("server error: ", error.message); return res.status(500).json({ success: false, error: "serverError" }); @@ -48,7 +69,16 @@ const showBoatById = async (req: Request, res: Response) => { const givenId = req.params.id; const boat = await Boat.findByPk(givenId); if (boat) { - return res.status(200).json({ success: true, result: boat }); + return res.status(200).json({ + success: true, + result: { + name: boat.name, + boatTypeId: boat.boattype, + status: boat.status, + active: boat.active, + tags: boat.tags, + }, + }); } return res.status(404).json({ success: false, error: "boatIdNotFound" }); } catch (error) { @@ -66,7 +96,7 @@ const deleteBoatById = async (req: Request, res: Response) => { .json({ success: false, error: "MustBeCoordinator" }); } const givenId = req.params.id; - const boatToDelete = await Boat.destroy({ + const boatToDelete = await Boat.destroy({ where: { id: givenId, }, @@ -83,7 +113,6 @@ const deleteBoatById = async (req: Request, res: Response) => { } }; - const boatControllers = { showAllBoatsController, showBoatById, diff --git a/server/src/controllers/boatTypeControllers.controllers.ts b/server/src/controllers/boatTypeControllers.controllers.ts index c020d3d094aa45282a2b3615ec70346f7b4cef36..dff49a0d2c10223daa9f5eeeb0b539a729f58e55 100644 --- a/server/src/controllers/boatTypeControllers.controllers.ts +++ b/server/src/controllers/boatTypeControllers.controllers.ts @@ -43,7 +43,7 @@ const showAllBoatTypes = async (req: Request, res: Response) => { return res.status(200).send({ success: true, result: allBoatTypes.map((boattype) => { - return { id: boattype.id, name: boattype.name, seats: boattype.seats }; + return { name: boattype.name, seats: boattype.seats }; }), }); } catch (error) { @@ -78,7 +78,7 @@ const deleteBoatTypeById = async (req: Request, res: Response) => { } }; -//show type of a boat using boat's id +//show boatType using boat's id const showBoatTypeById = async (req: Request, res: Response) => { try { if (!(res.locals.user.role === "coordinator")) { diff --git a/server/src/controllers/userControllers.controllers.ts b/server/src/controllers/userControllers.controllers.ts index d1517a936b0861ae6017c42983a326b8cb8081a1..5052179050ea81d4cc79899823bc8520796f02a1 100644 --- a/server/src/controllers/userControllers.controllers.ts +++ b/server/src/controllers/userControllers.controllers.ts @@ -12,14 +12,25 @@ const showCurrentUserController = async (req: Request, res: Response) => { }, }); - res.status(200).json({ success: true, result: currentUserData }); + res + .status(200) + .json({ + success: true, + result: { + id: currentUserData.id, + first_name: currentUserData.first_name, + last_name: currentUserData.last_name, + email: currentUserData.email, + role: currentUserData.role, + }, + }); } catch (error) { console.log("server error: ", error.message); res.status(500).json({ success: false, error: "serverError!" }); } }; -//update current user PATCH +//update current user PATCH const updateCurrentUser = async (req: Request, res: Response) => { try { //check role