diff --git a/client/src/router/guards/guards.js b/client/src/router/guards/guards.js index 55d3267..a5d7b82 100644 --- a/client/src/router/guards/guards.js +++ b/client/src/router/guards/guards.js @@ -110,4 +110,9 @@ export async function isInitingFuncionario(){ export async function isInitingProfessor(){ return (Cookies.get('email-init-professor')) ? true : false; +} + +// isCompleted +export async function isCompletedAluno(){ + return (Cookies.get('completed') && Cookies.get('completed') == true && await isAuthAluno() ? true : false) ? true : false; } \ No newline at end of file diff --git a/client/src/router/routes/aluno.js b/client/src/router/routes/aluno.js index 9142015..5416238 100644 --- a/client/src/router/routes/aluno.js +++ b/client/src/router/routes/aluno.js @@ -5,11 +5,13 @@ import RecoveryAluno from '../../views/aluno/Recovery.vue'; import ValidateRecovery from '../../views/aluno/ValidateRecovery.vue'; import HomeAluno from '../../views/aluno/Home.vue'; import PerfilAluno from '../../views/aluno/Profile.vue'; +import Complete from '../../views/aluno/Complete.vue'; import { isRecoveringAluno, isRegistering, - isAuthAluno + isAuthAluno, + isCompletedAluno } from '../guards/guards.js'; export const alunoRoutes = [ @@ -57,7 +59,12 @@ export const alunoRoutes = [ name: "PerfilAluno", component: PerfilAluno, beforeEnter: async (to, from, next) => { - (await isAuthAluno()) ? next() : next("/login"); + (await isCompletedAluno()) ? next() : next("/register/complete"); } + }, + { + path: "/register/complete", + name: "Complete", + component: Complete } ]; \ No newline at end of file diff --git a/client/src/services/api.js b/client/src/services/api.js index d5145e5..e27fc53 100644 --- a/client/src/services/api.js +++ b/client/src/services/api.js @@ -1,8 +1,8 @@ import axios from 'axios'; const api = axios.create({ - baseURL: 'https://536a8c3ee76a5fd349ca5407510dde61.serveo.net' - // baseURL: 'http://localhost:3333/' + // baseURL: 'https://536a8c3ee76a5fd349ca5407510dde61.serveo.net' + baseURL: 'http://localhost:3333/' }); export default api; \ No newline at end of file diff --git a/client/src/services/api/aluno.js b/client/src/services/api/aluno.js index c93c58f..bddbc29 100644 --- a/client/src/services/api/aluno.js +++ b/client/src/services/api/aluno.js @@ -40,6 +40,15 @@ export const registerAluno = async(userAluno) => { } } +export const completeRegister = async(infoAluno) => { + try { + const response = await api.post('aluno/register/complete/', infoAluno); + return response; + } catch (error) { + return error.response.data; + } +} + export const recoveryAluno = async(infoAluno) => { try { const response = await api.post('aluno/recovery', infoAluno); diff --git a/client/src/views/aluno/Complete.vue b/client/src/views/aluno/Complete.vue new file mode 100644 index 0000000..ea9dad4 --- /dev/null +++ b/client/src/views/aluno/Complete.vue @@ -0,0 +1,320 @@ + + + + + + + Termine seu registro + + Nascimento + + + + + + Endereco + + + + + Turma + + + + + + RM + + + + + + Finalizar + Finalizar + + + + + + + + + + + \ No newline at end of file diff --git a/client/src/views/aluno/Login.vue b/client/src/views/aluno/Login.vue index 8ac2bf7..a9e0327 100644 --- a/client/src/views/aluno/Login.vue +++ b/client/src/views/aluno/Login.vue @@ -97,10 +97,13 @@ export default { }); if (response.status >= 200 && response.status < 300) { - if (Cookies.get('token')) { - Cookies.remove('token'); - } - document.cookie = `token=${response.data.token}`; + (Cookies.get('token'))? Cookies.remove('token') : null; + (Cookies.get('email-aluno'))? Cookies.remove('email-aluno') : null; + (Cookies.get('completed'))? Cookies.remove('completed') : null; + + Cookies.set("token",`${response.data.token}`); + Cookies.set("completed", (response.data.aluno.rm? "true" : "false")); + Cookies.set('email-aluno', this.userAluno.email) router.push({ path: '/aluno'}); alert("Tudo certo! đŸ˜‰"); diff --git a/server/prisma/migrations/20240521003302_add_new_table_vincolos_and_addcolumns/migration.sql b/server/prisma/migrations/20240521003302_add_new_table_vincolos_and_addcolumns/migration.sql index d7f1893..a982f39 100644 --- a/server/prisma/migrations/20240521003302_add_new_table_vincolos_and_addcolumns/migration.sql +++ b/server/prisma/migrations/20240521003302_add_new_table_vincolos_and_addcolumns/migration.sql @@ -1,3 +1,4 @@ +-- SQLBook: Code /* Warnings: diff --git a/server/src/modules/controllers/alunoControllers.ts b/server/src/modules/controllers/alunoControllers.ts index 6eedd4f..d585df6 100644 --- a/server/src/modules/controllers/alunoControllers.ts +++ b/server/src/modules/controllers/alunoControllers.ts @@ -5,6 +5,7 @@ import { LoginAlunoUseCase } from "../services/aluno/LoginAlunoUseCase"; import { RecoveryAluno } from "../services/aluno/RecoveryAlunoUseCase"; import { ValidateRecoveryUseCase } from "../services/aluno/ValidateRecoveryUseCase"; import { CompleteAlunoUseCase } from "../services/aluno/CompleteRegisterUseCase"; +import { UpdateCurriculoUseCase } from "../services/aluno/UpdateCurriculoUseCase"; export class CreateAlunoController { async handle(req: Request, res: Response) { @@ -66,7 +67,6 @@ export class ValidateRecoveryController { } } - export class CompleteAlunoController { async handle(req: Request, res: Response) { const { email, nascimento, endereco, turma, rm } = req.body; @@ -75,6 +75,18 @@ export class CompleteAlunoController { const result = await completeAluno.execute({ email, nascimento, endereco, turma, rm }); + return res.status(201).json(result); + } +} + +export class UpdateCurriculoController { + async handle(req: Request, res: Response) { + const { email, curriculo } = req.body; + + const updateCurriculo = new UpdateCurriculoUseCase(); + + const result = await updateCurriculo.execute({ email, curriculo }); + return res.status(201).json(result); } } \ No newline at end of file diff --git a/server/src/modules/interfaces/alunoDTOs.ts b/server/src/modules/interfaces/alunoDTOs.ts index db1fd05..ecc18ed 100644 --- a/server/src/modules/interfaces/alunoDTOs.ts +++ b/server/src/modules/interfaces/alunoDTOs.ts @@ -31,4 +31,9 @@ export interface CompleteAlunoDTO { turma: string, rm: string endereco: string +} + +export interface UpdateCurriculoDTO { + email: string, + curriculo: string } \ No newline at end of file diff --git a/server/src/modules/services/aluno/CompleteRegisterUseCase.ts b/server/src/modules/services/aluno/CompleteRegisterUseCase.ts index d919b76..beea7b8 100644 --- a/server/src/modules/services/aluno/CompleteRegisterUseCase.ts +++ b/server/src/modules/services/aluno/CompleteRegisterUseCase.ts @@ -1,15 +1,14 @@ -import { Aluno } from "@prisma/client"; import { prisma } from "../../../prisma/client"; import { CompleteAlunoDTO } from "../../interfaces/alunoDTOs" import { AppError } from "../../../errors/error"; export class CompleteAlunoUseCase { - async execute({ email, nascimento, endereco, turma, rm }: CompleteAlunoDTO): Promise>{ + async execute({ email, nascimento, endereco, turma, rm }: CompleteAlunoDTO) { - if( !email || !nascimento || !endereco || !turma || !rm ){ + if (!email || !nascimento || !endereco || !turma || !rm) { throw new AppError("ParĂ¢metros insuficientes ou invĂ¡lidos."); } - + const aluno = await prisma.aluno.findUnique({ where: { email @@ -17,16 +16,16 @@ export class CompleteAlunoUseCase { }); if (aluno) { - const rmAlreadyExists = await prisma.aluno.findUnique({ - where: { + const rmAlreadyExists = await prisma.aluno.findFirst({ + where: { rm } }); - if (!rmAlreadyExists){ - const CompleteAluno = prisma.aluno.update({ + if (!rmAlreadyExists) { + prisma.aluno.update({ where: { - email + email }, data: { dataNascimento: nascimento, @@ -36,8 +35,8 @@ export class CompleteAlunoUseCase { } }); - return CompleteAluno; - } else{ + return; + } else { throw new AppError("RM jĂ¡ cadastrado"); } } else { diff --git a/server/src/modules/services/aluno/LoginAlunoUseCase.ts b/server/src/modules/services/aluno/LoginAlunoUseCase.ts index 5bcf471..1f60395 100644 --- a/server/src/modules/services/aluno/LoginAlunoUseCase.ts +++ b/server/src/modules/services/aluno/LoginAlunoUseCase.ts @@ -7,12 +7,12 @@ import { generateAccessTokenAluno } from "../../../jwt/jwtServices"; const bcrypt = require('bcrypt'); export class LoginAlunoUseCase { - async execute({ email, password }: LoginAlunoDTO): Promise<{ token: string, aluno: Pick }> { + async execute({ email, password }: LoginAlunoDTO): Promise<{ token: string, aluno: Pick }> { if( !email || !password ){ throw new AppError("ParĂ¢metros insuficientes ou invĂ¡lidos."); } - + const aluno = await prisma.aluno.findFirst({ where: { email @@ -39,7 +39,8 @@ export class LoginAlunoUseCase { token: token, aluno: { name: aluno.name, - email: aluno.email + email: aluno.email, + rm: aluno.rm } } } diff --git a/server/src/modules/services/aluno/UpdateCurriculoUseCase.ts b/server/src/modules/services/aluno/UpdateCurriculoUseCase.ts new file mode 100644 index 0000000..52440f5 --- /dev/null +++ b/server/src/modules/services/aluno/UpdateCurriculoUseCase.ts @@ -0,0 +1,33 @@ +import { prisma } from "../../../prisma/client"; +import { UpdateCurriculoDTO } from "../../interfaces/alunoDTOs" +import { AppError } from "../../../errors/error"; + +export class UpdateCurriculoUseCase { + async execute({ email, curriculo }: UpdateCurriculoDTO) { + + if (!email || !curriculo) { + throw new AppError("ParĂ¢metros insuficientes ou invĂ¡lidos."); + } + + const aluno = await prisma.aluno.findUnique({ + where: { + email + } + }); + + if (aluno) { + await prisma.aluno.update({ + where: { + email + }, + data: { + curriculo: curriculo + } + }); + + return; + } else { + throw new AppError("Email nĂ£o encontrado"); + } + } +} \ No newline at end of file diff --git a/server/src/router/routes/aluno.routes.ts b/server/src/router/routes/aluno.routes.ts index 1afe924..e73dc63 100644 --- a/server/src/router/routes/aluno.routes.ts +++ b/server/src/router/routes/aluno.routes.ts @@ -6,7 +6,8 @@ import { LoginAlunoController, RecoveryAlunoController, ValidateRecoveryController, - CompleteAlunoController + CompleteAlunoController, + UpdateCurriculoController } from "../../modules/controllers/alunoControllers"; const createPreAlunoController = new CreatePreAlunoController(); @@ -15,12 +16,14 @@ const loginAlunoController = new LoginAlunoController(); const recoveryAlunoController = new RecoveryAlunoController(); const validateRecoveryController = new ValidateRecoveryController(); const completeAlunoController = new CompleteAlunoController(); +const updateCurriculoController = new UpdateCurriculoController(); const alunoRoutes = Router(); alunoRoutes.post("/register/prealuno", createPreAlunoController.handle); alunoRoutes.post("/register", createAlunoUseController.handle); alunoRoutes.post("/register/complete", alunoAuthMiddleware, completeAlunoController.handle); +alunoRoutes.post("/update/curriculo", alunoAuthMiddleware, updateCurriculoController.handle); alunoRoutes.post("/login", loginAlunoController.handle); alunoRoutes.post("/recovery", recoveryAlunoController.handle); alunoRoutes.post("/recovery/validate", validateRecoveryController.handle);