Skip to content

Commit

Permalink
Merge pull request #57 from codexjr-dev/dev
Browse files Browse the repository at this point in the history
Sprint 3: Dev to Main
  • Loading branch information
ManoMax authored Sep 11, 2023
2 parents 821a757 + 89e4410 commit b8a8802
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 92 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tcc-backend",
"version": "1.0.0",
"name": "projexa",
"version": "1.2.3",
"description": "API do gerenciador de EJs",
"main": "index.js",
"scripts": {
Expand All @@ -11,14 +11,14 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/lucasanthony/tcc-backend.git"
"url": "git+https://github.com/codexjr-dev/dashboard-codex-api.git"
},
"author": "Lucas Anthony",
"author": "CodeX Jr.",
"license": "ISC",
"bugs": {
"url": "https://github.com/lucasanthony/tcc-backend/issues"
"url": "https://github.com/codexjr-dev/dashboard-codex-api/issues"
},
"homepage": "https://github.com/lucasanthony/tcc-backend#readme",
"homepage": "https://github.com/codexjr-dev/dashboard-codex-api#readme",
"dependencies": {
"bcrypt": "^5.0.1",
"body-parser": "^1.19.1",
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ const authorize = (req, res, next, type) => {
};

const isLeadership = (member) =>
["Presidente", "Diretor(a)"].includes(`${member.role}`);
member && ["Presidente", "Diretor(a)"].includes(`${member.role}`);
35 changes: 31 additions & 4 deletions src/modules/Ej/EjService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ module.exports = {
})

newMember.password = undefined
return { ej: ej, member: newMember }
return { ej: getDTOej(ej), member: getDTOmember(newMember) }
},

// only for test purposes
async findAll() {
// const ejs = await Ej.find().populate({ path: 'president', select: 'name -_id' });
const ejs = await Ej.find();

return ejs;
const ejsDTO = ejs.map((ej) => {
return getDTOej(ej);
});

return ejsDTO;
},

async findPresident(ejId) {
Expand All @@ -47,6 +51,29 @@ module.exports = {

async findById(ejId) {
const ej = await Ej.findOne({ _id: ejId });
return ej;
return getDTOej(ej);
},
}
}

function getDTOej(ej) {
return {
_id: ej._id,
name: ej.name
};
}

function getDTOmember(member) {
return {
_id: member._id,
name: member.name,
email: member.email,
role: member.role,
ej: member.ej,
birthDate: member.birthDate,
entryDate: member.entryDate,
phone: member.phone,
observations: member.observations,
habilities: member.habilities,
department: member.department,
};
}
65 changes: 39 additions & 26 deletions src/modules/Link/Link.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
const { Schema, model } = require('mongoose');
const Ej = require('@ej/Ej')
const { Schema, model } = require("mongoose");
const Ej = require("@ej/Ej");

const LinkSchema = new Schema({
const LinkSchema = new Schema(
{
name: {
type: String,
required: true
type: String,
required: true,
},
url: {
type: String,
required: true
type: String,
required: true,
},
tags: [{
tags: [
{
type: String,
enum: ['importante', 'treinamento'],
required: false
}],
enum: ["Importante", "Treinamento", "Documentação"],
required: false,
},
],
ej: {
type: Schema.Types.ObjectId,
ref: Ej,
required: true
type: Schema.Types.ObjectId,
ref: Ej,
required: true,
},
departments: [{
departments: [
{
type: String,
enum: ['projetos', 'qualidade', 'presedência', 'pessoas'],
required: false
}],
enum: [
"Presidência",
"Gente & Gestão",
"Projetos",
"Qualidade",
"Marketing",
"Negócios",
],
required: false,
},
],
observations: {
type: String,
required: false
}
},
{
timestamps: true,
});
type: String,
required: false,
},
},
{
timestamps: true,
}
);

module.exports = model('Link', LinkSchema);
module.exports = model("Link", LinkSchema);
24 changes: 20 additions & 4 deletions src/modules/Link/LinkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,40 @@ module.exports = {
observations
})

return link;
return getDTOlink(link);
},

// only for test purposes
async findByEj(ejId) {
// const ejs = await Ej.find().populate({ path: 'president', select: 'name -_id' });
const links = await Link.find({ ej: ejId });

return links;
const linksDTO = links.map((link) => {
return getDTOlink(link);
});

return linksDTO;
},

async remove(linkId) {
const link = await Link.deleteOne({ _id: linkId });
return link;
return getDTOlink(link);
},

async update(linkId, data) {
const updatedLink = await Link.findOneAndUpdate({ _id: linkId }, data)
return updatedLink
return getDTOlink(updatedLink);
}
}

function getDTOlink(link) {
return {
_id: link._id,
name: link.name,
url: link.url,
tags: link.tags,
departments: link.departments,
ej: link.ej,
observations: link.observations
}
}
2 changes: 1 addition & 1 deletion src/modules/Member/Member.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const MemberSchema = new Schema({
},
role: {
type: String,
enum: ["Presidente", "Diretor(a)", "Assessor(a)", "Conselheiro(a)"],
enum: ["Presidente", "Diretor(a)", "Assessor(a)", "Conselheiro(a)", "Pós-Júnior", "Guardiã(o)", "Trainee", "Ex-Trainee"],
required: true,
default: "Assessor(a)",
},
Expand Down
76 changes: 43 additions & 33 deletions src/modules/Member/MemberController.js
Original file line number Diff line number Diff line change
@@ -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 });
}
}
},
};
Loading

0 comments on commit b8a8802

Please sign in to comment.