Skip to content

Commit

Permalink
Merge pull request #36 from fga-eps-mds/develop
Browse files Browse the repository at this point in the history
Release 2
  • Loading branch information
gabiMSilva authored Dec 14, 2020
2 parents 10f1e8b + 077be62 commit 897649c
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 331 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=fga-eps-mds_2020.1-Minacademy-BackEnd&metric=ncloc)](https://sonarcloud.io/dashboard?id=fga-eps-mds_2020.1-Minacademy-BackEnd) [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=fga-eps-mds_2020.1-Minacademy-BackEnd&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=fga-eps-mds_2020.1-Minacademy-BackEnd)

Repositório do BackEnd do projeto [Minacademy](https://github.com/fga-eps-mds/2020.1-Grupo4).
Repositório do BackEnd do projeto [Minacademy](https://github.com/fga-eps-mds/2020.1-Minacademy-Wiki).

## Executando o projeto

Expand Down
89 changes: 89 additions & 0 deletions seeds/answerkeys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[{
"_id": {
"$oid": "5fc155b6ae48d10016db5283"
},
"user": { "$oid": "5fb52c04c519d10015f9790b" },
"answers": [
{
"_id": {
"$oid": "5fc155b6ae48d10016db5284"
},
"question": "5f961e56fc13ae454d000014",
"alternative": "c",
"isCorrect": "hidden"
},
{
"_id": {
"$oid": "5fc155b9ae48d10016db5285"
},
"question": "5f961e56fc13ae454d000015",
"alternative": "c",
"isCorrect": "hidden"
},
{
"_id": {
"$oid": "5fc155bcae48d10016db5286"
},
"question": "5f961e56fc13ae454d000016",
"alternative": "c",
"isCorrect": "hidden"
},
{
"_id": {
"$oid": "5fc155b6ae48d10016db5287"
},
"question": "5f961e56fc13ae454d000017",
"alternative": "c",
"isCorrect": "hidden"
},
{
"_id": {
"$oid": "5fc155b9ae48d10016db5288"
},
"question": "5f961e56fc13ae454d000018",
"alternative": "c",
"isCorrect": "hidden"
},
{
"_id": {
"$oid": "5fc155bcae48d10016db5289"
},
"question": "5f961e56fc13ae454d000019",
"alternative": "c",
"isCorrect": "hidden"
},
{
"_id": {
"$oid": "5fc155b6ae48d10016db528a"
},
"question": "5f961e56fc13ae454d00001a",
"alternative": "c",
"isCorrect": "hidden"
},
{
"_id": {
"$oid": "5fc155b9ae48d10016db528b"
},
"question": "5f961e56fc13ae454d00001b",
"alternative": "c",
"isCorrect": "hidden"
},
{
"_id": {
"$oid": "5fc155bcae48d10016db528c"
},
"question": "5f961e56fc13ae454d00001c",
"alternative": "c",
"isCorrect": "hidden"
},
{
"_id": {
"$oid": "5fc155b6ae48d10016db528d"
},
"question": "5f961e56fc13ae454d00001d",
"alternative": "c",
"isCorrect": "hidden"
}
],
"__v": 2
}]
4 changes: 4 additions & 0 deletions seeds/chats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[{
"messages": [],
"users": [{ "$oid": "5fb52c04c519d10015f9791c" }, { "$oid": "5fb835b05acb1c001550621e" }]
}]
19 changes: 19 additions & 0 deletions seeds/coursecertificates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"_id": {
"$oid": "5fc07ddb1c18fa00154e0130"
},
"assignedPartner" : null,
"workload" : 6,
"user": { "$oid": "5fb835b05acb1c001550620f" },
"courseType" : "Learner",
"key" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZmI4MzViMDVhY2IxYzAwMTU1MDYyMGYiLCJpYXQiOjE2MDY0NTA2NTF9.Q1GTDeWMNTfoQS1naHGlOlAShuj5Z0st55B1sKh-PcE",
"createdAt" : {
"$date" : "2020-11-27T04:17:31.941Z"
},
"updatedAt" : {
"$date" : "2020-11-27T04:17:31.941Z"
},
"__v" : 0
}
]
148 changes: 75 additions & 73 deletions seeds/users.json
Original file line number Diff line number Diff line change
@@ -1,92 +1,94 @@
[
{
"_id": {
"$oid": "5f4fedaefc13ae5380000000"
},
"name": "Rosalyn",
"email": "[email protected]",
"password": "teste123"
},
{
"_id": {
"$oid": "5f4fedaefc13ae5380000001"
"_id" : {
"$oid": "5fb835b05acb1c001550620f"
},
"name": "Jacquie",
"email": "[email protected]"
"completedModules" : [],
"mentor_request" : true,
"mentor" : null,
"noAssociations" : [],
"courseCertificates" : ["5fc07ddb1c18fa00154e0130"],
"showMessageConfirm" : false,
"isRegistered" : true,
"userType" : "Learner",
"name" : "learner",
"lastname" : "cypress",
"email" : "[email protected]",
"gender" : "Female",
"password" : "$2a$10$tal0QZcxBwMjKuUEkKY8SORjbKsYobQFmtf9oNWUfSpls5pb.zIsC",
"tokens" : [],
"__v" : 4,
"registerLink" : ""
},
{
"_id": {
"$oid": "5f4fedaefc13ae5380000002"
"_id" : {
"$oid" : "5fb52c04c519d10015f9790b"
},
"name": "Ami",
"email": "[email protected]"
"completedModules" : [],
"mentor_request" : false,
"noAssociations" : [],
"courseCertificates" : ["5fb835bf5acb1c0015506210"],
"showMessageConfirm" : false,
"userType" : "Mentor",
"name" : "mentor",
"lastname" : "user",
"email" : "[email protected]",
"isRegistered" : true,
"gender" : "Female",
"password" : "$2a$10$cfzgMfS.TqrYAo95.ChTNOGzbCt/y3XZyKPETncjeUSjr//p863g2",
"tokens" : [],
"__v" : 7,
"registerLink" : "",
"attempts" : 3,
"isAvailable" : false,
"isValidated" : false,
"learners" : []
},
{
"_id": {
"$oid": "5f4fedaefc13ae5380000003"
"_id" : {
"$oid": "5fb835b05acb1c001550621e"
},
"name": "Vassili",
"email": "[email protected]"
},
{
"_id": {
"$oid": "5f4fedaefc13ae5380000004"
"completedModules" : [],
"mentor_request" : false,
"mentor" : {
"$oid" : "5fb52c04c519d10015f9791c"
},
"name": "Ag",
"email": "[email protected]"
"noAssociations" : [],
"courseCertificates" : [],
"showMessageConfirm" : false,
"isRegistered" : true,
"userType" : "Learner",
"name" : "chatTest",
"lastname" : "cypress",
"email" : "[email protected]",
"gender" : "Female",
"password" : "$2a$10$tal0QZcxBwMjKuUEkKY8SORjbKsYobQFmtf9oNWUfSpls5pb.zIsC",
"tokens" : [],
"__v" : 4,
"registerLink" : ""
},
{
"_id" : {
"$oid": "5f90d06cc0761408c778ec06"
"$oid" : "5fb52c04c519d10015f9791c"
},
"completedModules" : [
"5f652249fc13ae49f0000000",
"5f652249fc13ae49f0000001",
"5f652249fc13ae49f0000002",
"5f652249fc13ae49f0000003",
"5f652249fc13ae49f0000004",
"5f652249fc13ae49f0000005",
"5f652249fc13ae49f0000006",
"5f652249fc13ae49f0000007",
"5f652249fc13ae49f0000008",
"5f652249fc13ae49f0000009",
"5f652249fc13ae49f000000b",
"5f652249fc13ae49f000000c",
"5f652249fc13ae49f000000a",
"5f652249fc13ae49f000000d",
"5f652249fc13ae49f000000e",
"5f652249fc13ae49f000000f",
"5f652249fc13ae49f0000010",
"5f652249fc13ae49f0000011",
"5f652249fc13ae49f0000012",
"5f652249fc13ae49f0000013",
"5f652249fc13ae49f0000014",
"5f652249fc13ae49f0000015",
"5f652249fc13ae49f0000016",
"5f652249fc13ae49f0000017",
"5f652249fc13ae49f0000018"
],
"completedModules" : [],
"mentor_request" : false,
"mentor" : "5f93356c2a8adb116f2eff4e",
"about" : "",
"noAssociations" : [],
"courseCertificates" : [
"5f9b0e2dd7eedf019c17c763"
],
"userType" : "Learner",
"email" : "[email protected]",
"name" : "aprendiz7",
"lastname" : "aprendiz7",
"courseCertificates" : [],
"showMessageConfirm" : false,
"userType" : "Mentor",
"name" : "chatTest",
"lastname" : "cypress",
"email" : "[email protected]",
"isRegistered" : true,
"gender" : "Female",
"password" : "$2a$10$51fg1fyzOuM7WiDHMLgMSOQkd0z1Fyoabp3vuOubx7Tj/0Voz9fee",
"tokens" : [
{
"_id" : "5f90d06cc0761408c778ec07",
"accessToken" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVmOTBkMDZjYzA3NjE0MDhjNzc4ZWMwNiIsImlhdCI6MTYwMzMyNjA2MH0.F6ScYAM9JbbLgwTsGK2gOzCHgUFGz1vSR61DbJXZWYo"
}
],
"createdAt" : "2020-10-22T00:21:00.610Z",
"updatedAt" : "2020-10-29T18:47:09.534Z",
"__v" : 111
"password" : "$2a$10$cfzgMfS.TqrYAo95.ChTNOGzbCt/y3XZyKPETncjeUSjr//p863g2",
"tokens" : [],
"__v" : 7,
"registerLink" : "",
"attempts" : 2,
"isAvailable" : false,
"isValidated" : true,
"learners" : [{ "$oid": "5fb835b05acb1c001550621e" }]
}
]
5 changes: 2 additions & 3 deletions server/controllers/AnswersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ const Question = require('../models/Question');
const AnswerKeys = require('../models/AnswerKey');
const { isCorrect } = require('../utils/answerKeysUtils');

/* eslint-disable max-len */
module.exports = {
async answerQuestion(req, res) {
try {
const question = await Question.findById(req.body.question);
if (!question) throw new Error('Question not found');
const newAnswer = {
question: req.body.question,
alternative: req.body.alternative,
isCorrect: isCorrect(question, req.body.alternative),
question: req.body.question, alternative: req.body.alternative, isCorrect: isCorrect(question, req.body.alternative),
};
let answerKeys = await req.user
.execPopulate('answers')
Expand Down
24 changes: 6 additions & 18 deletions server/controllers/LearnerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@ module.exports = {
}
},

/* eslint-disable max-len */
async assignMentor(req, res) {
const learner = req.user;

try {
learner.mentor_request = true;
await learner.save();
if (learner.mentor) throw new Error('Learner already has a mentor');
let mentor = (await Mentor.aggregate()
.match({ isAvailable: true, isValidated: true, _id: { $nin: learner.noAssociations } })
.group({
_id: '$_id',
size: { $max: '$learners' },
createdAt: { $min: '$createdAt' } // eslint-disable-line comma-dangle
})
.sort({ createdAt: 'asc', size: 1 }))[0];
let mentor = (await Mentor.aggregate().match({ isAvailable: true, isValidated: true, _id: { $nin: learner.noAssociations } })
.group({ _id: '$_id', size: { $max: '$learners' }, createdAt: { $min: '$createdAt' } }).sort({ createdAt: 'asc', size: 1 }))[0]; // eslint-disable-line comma-dangle
/* eslint-disable quotes */
/* eslint-disable quote-props */
if (!mentor) throw new Error('There are no available mentors');
Expand Down Expand Up @@ -95,7 +90,7 @@ module.exports = {
res.status(400).send({ mentor: learner.mentor, error: error.message });
}
},

/* eslint-disable max-len */
async promoteToMentor(req, res) {
const { _id } = req.user;
const reqUser = req.user;
Expand All @@ -104,21 +99,14 @@ module.exports = {

if (!hasLearnerCertificate) throw new Error('User did not conclude Tutorial');
if (reqUser.mentor) {
await User.findOneAndUpdate({ _id }, {
$pull: { learners: reqUser._id },
$push: { noAssociations: reqUser._id },
isAvailable: false,
});
await User.findOneAndUpdate({ _id }, { $pull: { learners: reqUser._id }, $push: { noAssociations: reqUser._id }, isAvailable: false });
reqUser.noAssociations.push(reqUser.mentor);
reqUser.mentor = null;
reqUser.save();
}
const user = await User.findByIdAndUpdate(
_id,
{
$set: { userType: 'Mentor' },
mentor_request: false,
}, { new: true },
{ $set: { userType: 'Mentor' }, mentor_request: false }, { new: true },
);
user.isValidated = true;
user.save();
Expand Down
6 changes: 2 additions & 4 deletions server/controllers/ModuleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ const checkModuleCompletion = async (module, user, answerKeys) => {
/* eslint-disable no-unused-expressions */
/* eslint-disable no-param-reassign */
if (!user.completedModules) user.completedModules = [];
if (obj.completed) {
user.completedModules.includes(module._id)
? (null)
: (user.completedModules = user.completedModules.concat(module._id));
if (obj.completed && !user.completedModules.includes(module._id)) {
user.completedModules = user.completedModules.concat(module._id);
}
return obj;
};
Expand Down
Loading

0 comments on commit 897649c

Please sign in to comment.