Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atualiza updateMembership #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/Controllers/membershipController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { sendEmail } = require("../Utils/email");
const Membership = require("../Models/membershipSchema");
const generator = require("generate-password");

Check failure on line 3 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

'generator' is assigned a value but never used
const bcrypt = require("bcryptjs");
const Token = require("../Models/tokenSchema");
const { generateRecoveryPasswordToken } = require("../Utils/token");
Expand Down Expand Up @@ -35,7 +35,7 @@

const sindRole = await Role.findOne({ name: "sindicalizado" });
if (!sindRole) {
console.error(

Check warning on line 38 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
'Role "sindicalizado" não encontrada. Crie a role antes de adicionar o usuário administrador.'
);
return;
Expand All @@ -54,12 +54,12 @@

await membership.save();
return res.status(201).send(membership);
} catch (error) {

Check failure on line 57 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
return res.status(500).send({ error });
}
};

const getMembershipForm = async (req, res) => {

Check warning on line 62 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
try {
const sindRole = await Role.findOne({ name: "sindicalizado" });
if (!sindRole) {
Expand All @@ -74,7 +74,7 @@
role: sindRole._id,
...(status && { status }), // Adiciona status apenas se existir
};

Check warning on line 77 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
const membership = await Membership.find(query);
return res.status(200).send(membership);
} catch (error) {
Expand Down Expand Up @@ -160,19 +160,34 @@
}
};

const updateMembership = async (req, res) => {

Check failure on line 163 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Delete `······`
try {
const userId = req.params.id;
const formData = req.body.formData;

Check failure on line 166 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`

Check failure on line 167 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
// Verificar se o CPF está em uso por outro usuário
const existingMembershipWithCpf = await Membership.findOne({
cpf: formData.cpf,

Check failure on line 170 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
_id: { $ne: userId }, // Ignorar o usuário que está sendo editado
});

Check failure on line 172 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Delete `······`
if (existingMembershipWithCpf) {
return res.status(400).send({ mensagem: "CPF já cadastrado." });
}

Check failure on line 175 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Delete `······`

// Encontrar e atualizar o usuário atual

Check failure on line 177 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Replace `return·res.status(404)` with `··return·res⏎················.status(404)⏎················`
const existingMembership = await Membership.findById(userId);


Check failure on line 179 in src/Controllers/membershipController.js

View workflow job for this annotation

GitHub Actions / lint

Delete `······`
if (!existingMembership) {
return res.status(404).send({ mensagem: "Usuário não encontrado." });
}

Object.assign(existingMembership, formData);

await existingMembership.save();
return res.status(201).send(existingMembership);
} catch (error) {
return res.status(200).send(existingMembership);
} catch (error) {
return res.status(500).send({ error });
}
}
};

module.exports = {
Expand Down
Loading