From 21b096774b5664f760e1dd5a601f54a208df386f Mon Sep 17 00:00:00 2001 From: ManoMax Date: Wed, 6 Sep 2023 08:54:39 -0300 Subject: [PATCH] feat: loged flag added to findByEj service --- src/modules/Member/MemberController.js | 76 +++++++++++++++----------- src/modules/Member/MemberService.js | 6 +- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/modules/Member/MemberController.js b/src/modules/Member/MemberController.js index 0f4d0d8..aee8f0a 100644 --- a/src/modules/Member/MemberController.js +++ b/src/modules/Member/MemberController.js @@ -1,39 +1,49 @@ -const { save, findByEj, remove, update } = require('./MemberService'); +const { save, findByEj, remove, update } = require("./MemberService"); module.exports = { - async save(req, res) { - try { - const member = await save(req.body, req.ejId); - return res.status(201).send({ member: member }); - } catch (error) { - return res.status(500).send({ error: error.message }); - } - }, + async save(req, res) { + try { + const member = await save(req.body, req.ejId); + return res.status(201).send({ member: member }); + } catch (error) { + return res.status(500).send({ error: error.message }); + } + }, - async findByEj(req, res) { - try { - const members = await findByEj(req.ejId); - return res.status(200).send({ members: members }); - } catch (error) { - return res.status(500).send({ error: error.message }); - } - }, + async findByEj(req, res) { + try { + const members = await findByEj(req); + return res.status(200).send({ members: members }); + } catch (error) { + return res.status(500).send({ error: error.message }); + } + }, - async remove(req, res) { - try { - const removedMember = await remove(req.params.id); - return res.status(200).send({ member: removedMember, message: 'Membero removido com sucesso!' }); - } catch (error) { - return res.status(500).send({ error: error.message }); - } - }, + async remove(req, res) { + try { + const removedMember = await remove(req.params.id); + return res + .status(200) + .send({ + member: removedMember, + message: "Membero removido com sucesso!", + }); + } catch (error) { + return res.status(500).send({ error: error.message }); + } + }, - async update(req, res) { - try { - const updatedMember = await update(req.params.id, req.body); - return res.status(200).send({ member: updatedMember, message: 'Membro atualizado com sucesso!' }); - } catch (error) { - return res.status(500).send({ error: error.message }); - } + async update(req, res) { + try { + const updatedMember = await update(req.params.id, req.body); + return res + .status(200) + .send({ + member: updatedMember, + message: "Membro atualizado com sucesso!", + }); + } catch (error) { + return res.status(500).send({ error: error.message }); } -} \ No newline at end of file + }, +}; diff --git a/src/modules/Member/MemberService.js b/src/modules/Member/MemberService.js index d06be1b..9de0295 100644 --- a/src/modules/Member/MemberService.js +++ b/src/modules/Member/MemberService.js @@ -40,11 +40,13 @@ module.exports = { }, // only for test purposes - async findByEj(ejId) { + async findByEj(req) { // const ejs = await Ej.find().populate({ path: 'president', select: 'name -_id' }); - const members = await Member.find({ ej: ejId }); + const members = await Member.find({ ej: req.ejId }); const membersDTO = members.map((member) => { + if (member._id.toString() === req.memberId.toString()) + return { ...getDTOmember(member), ...{ loged: true } }; return getDTOmember(member); });