diff --git a/README.md b/README.md index 72bdb61..259319c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/seeds/answerkeys.json b/seeds/answerkeys.json new file mode 100644 index 0000000..5a91b17 --- /dev/null +++ b/seeds/answerkeys.json @@ -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 +}] \ No newline at end of file diff --git a/seeds/chats.json b/seeds/chats.json new file mode 100644 index 0000000..5483295 --- /dev/null +++ b/seeds/chats.json @@ -0,0 +1,4 @@ +[{ + "messages": [], + "users": [{ "$oid": "5fb52c04c519d10015f9791c" }, { "$oid": "5fb835b05acb1c001550621e" }] +}] \ No newline at end of file diff --git a/seeds/coursecertificates.json b/seeds/coursecertificates.json new file mode 100644 index 0000000..3f571e3 --- /dev/null +++ b/seeds/coursecertificates.json @@ -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 + } +] \ No newline at end of file diff --git a/seeds/users.json b/seeds/users.json index fd61bee..461bcfc 100644 --- a/seeds/users.json +++ b/seeds/users.json @@ -1,92 +1,94 @@ [ { - "_id": { - "$oid": "5f4fedaefc13ae5380000000" - }, - "name": "Rosalyn", - "email": "rosalyn@email.com", - "password": "teste123" - }, - { - "_id": { - "$oid": "5f4fedaefc13ae5380000001" + "_id" : { + "$oid": "5fb835b05acb1c001550620f" }, - "name": "Jacquie", - "email": "jacquie@email.com" + "completedModules" : [], + "mentor_request" : true, + "mentor" : null, + "noAssociations" : [], + "courseCertificates" : ["5fc07ddb1c18fa00154e0130"], + "showMessageConfirm" : false, + "isRegistered" : true, + "userType" : "Learner", + "name" : "learner", + "lastname" : "cypress", + "email" : "user@email.com", + "gender" : "Female", + "password" : "$2a$10$tal0QZcxBwMjKuUEkKY8SORjbKsYobQFmtf9oNWUfSpls5pb.zIsC", + "tokens" : [], + "__v" : 4, + "registerLink" : "" }, { - "_id": { - "$oid": "5f4fedaefc13ae5380000002" + "_id" : { + "$oid" : "5fb52c04c519d10015f9790b" }, - "name": "Ami", - "email": "ami@email.com" + "completedModules" : [], + "mentor_request" : false, + "noAssociations" : [], + "courseCertificates" : ["5fb835bf5acb1c0015506210"], + "showMessageConfirm" : false, + "userType" : "Mentor", + "name" : "mentor", + "lastname" : "user", + "email" : "user@mentor.com", + "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": "vassili@email.com" - }, - { - "_id": { - "$oid": "5f4fedaefc13ae5380000004" + "completedModules" : [], + "mentor_request" : false, + "mentor" : { + "$oid" : "5fb52c04c519d10015f9791c" }, - "name": "Ag", - "email": "ag@email.com" + "noAssociations" : [], + "courseCertificates" : [], + "showMessageConfirm" : false, + "isRegistered" : true, + "userType" : "Learner", + "name" : "chatTest", + "lastname" : "cypress", + "email" : "chatTest@email.com", + "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" : "teste7@teste.com", - "name" : "aprendiz7", - "lastname" : "aprendiz7", + "courseCertificates" : [], + "showMessageConfirm" : false, + "userType" : "Mentor", + "name" : "chatTest", + "lastname" : "cypress", + "email" : "chat@mentor.com", + "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" }] } ] \ No newline at end of file diff --git a/server/controllers/AnswersController.js b/server/controllers/AnswersController.js index da84b6e..4a15dfe 100644 --- a/server/controllers/AnswersController.js +++ b/server/controllers/AnswersController.js @@ -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') diff --git a/server/controllers/LearnerController.js b/server/controllers/LearnerController.js index c3ed4c2..700844c 100644 --- a/server/controllers/LearnerController.js +++ b/server/controllers/LearnerController.js @@ -16,6 +16,7 @@ module.exports = { } }, + /* eslint-disable max-len */ async assignMentor(req, res) { const learner = req.user; @@ -23,14 +24,8 @@ module.exports = { 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'); @@ -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; @@ -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(); diff --git a/server/controllers/ModuleController.js b/server/controllers/ModuleController.js index ca920d3..58822c3 100644 --- a/server/controllers/ModuleController.js +++ b/server/controllers/ModuleController.js @@ -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; }; diff --git a/server/mail/data.js b/server/mail/data.js index 0c5484a..d725960 100644 --- a/server/mail/data.js +++ b/server/mail/data.js @@ -7,7 +7,6 @@ const mailBuilder = (email, subject, message) => { // eslint-disable-line arrow- to: email, subject, html: ` -