Skip to content

Commit

Permalink
Merge pull request #25 from Daniel-Alvarenga/main
Browse files Browse the repository at this point in the history
Create Send Message Routes
  • Loading branch information
Daniel-Alvarenga authored Jun 17, 2024
2 parents 63e05c5 + 6159683 commit 982e028
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 95 deletions.
19 changes: 19 additions & 0 deletions client/src/services/api/aluno.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,23 @@ export const changePassword = async (info, token) => {
} catch (error) {
return error.response.data;
}
}

export const sendMessage = async (infoMesssage, token) => {
try {
const response = await api.post('aluno/message/send', infoMesssage, {
headers: {
authorization: `${token}`
}
});

socket.emit('send-message', {
message: infoMesssage,
authorization: `${token}`
});

return response;
} catch (error) {
return error.data;
}
}
19 changes: 19 additions & 0 deletions client/src/services/api/professor.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,23 @@ export const refreshTokenProfessor = async (token) => {
} catch (error) {
return error.response.data;
}
}

export const sendMessage = async (infoMesssage, token) => {
try {
const response = await api.post('professor/message/send', infoMesssage, {
headers: {
authorization: `${token}`
}
});

socket.emit('send-message', {
message: infoMesssage,
authorization: `${token}`
});

return response;
} catch (error) {
return error.data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- CreateTable
CREATE TABLE `mensagens` (
`id` VARCHAR(191) NOT NULL,
`conteudo` VARCHAR(191) NOT NULL,
`alunoRemetenteId` VARCHAR(191) NULL,
`alunoDestinatarioId` VARCHAR(191) NULL,
`professorRemetenteId` VARCHAR(191) NULL,
`professorDestinatarioId` VARCHAR(191) NULL,
`funcionarioRemetenteId` VARCHAR(191) NULL,
`funcionarioDestinatarioId` VARCHAR(191) NULL,
`empresaRemetenteId` VARCHAR(191) NULL,
`empresaDestinatarioId` VARCHAR(191) NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updatedAt` DATETIME(3) NOT NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `mensagens` ADD CONSTRAINT `alunoRemetente_FK` FOREIGN KEY (`alunoRemetenteId`) REFERENCES `alunos`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `mensagens` ADD CONSTRAINT `alunoDestinatario_FK` FOREIGN KEY (`alunoDestinatarioId`) REFERENCES `alunos`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `mensagens` ADD CONSTRAINT `professorRemetente_FK` FOREIGN KEY (`professorRemetenteId`) REFERENCES `professores`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `mensagens` ADD CONSTRAINT `professorDestinatario_FK` FOREIGN KEY (`professorDestinatarioId`) REFERENCES `professores`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `mensagens` ADD CONSTRAINT `funcionarioRemetente_FK` FOREIGN KEY (`funcionarioRemetenteId`) REFERENCES `funcionarios`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `mensagens` ADD CONSTRAINT `funcionarioDestinatario_FK` FOREIGN KEY (`funcionarioDestinatarioId`) REFERENCES `funcionarios`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `mensagens` ADD CONSTRAINT `empresaRemetente_FK` FOREIGN KEY (`empresaRemetenteId`) REFERENCES `empresas`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `mensagens` ADD CONSTRAINT `empresaDestinatario_FK` FOREIGN KEY (`empresaDestinatarioId`) REFERENCES `empresas`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
177 changes: 105 additions & 72 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,29 @@ datasource db {
}

model Aluno {
id String @id @default(uuid())
name String
email String @unique
password String
imagem String?
recoveryPass String?
token String?
banner String?
dataNascimento DateTime?
endereco String?
curriculo String? @default("") @db.VarChar(5000)
sobre String?
rm String? @unique
tentativasRestantes Int @default(5)
turmas AlunoTurma[]
cursosExtracurriculares Extracurricular[]
vinculosAluno Vinculo[] @relation("AlunoVinculo")
vinculoComoAluno Vinculo[] @relation("VinculoComAluno")
validated Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
id String @id @default(uuid())
name String
email String @unique
password String
imagem String?
recoveryPass String?
token String?
banner String?
dataNascimento DateTime?
endereco String?
curriculo String? @default("") @db.VarChar(5000)
sobre String?
rm String? @unique
tentativasRestantes Int @default(5)
validated Boolean @default(false)
turmas AlunoTurma[]
cursosExtracurriculares Extracurricular[]
vinculosAluno Vinculo[] @relation("AlunoVinculo")
vinculoComoAluno Vinculo[] @relation("VinculoComAluno")
mensagensEnviadas Mensagem[] @relation("MensagensEnviadasAluno")
mensagensRecebidas Mensagem[] @relation("MensagensRecebidasAluno")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("alunos")
}
Expand All @@ -43,11 +45,13 @@ model Professor {
imagem String?
banner String?
validated Boolean @default(false)
coordenador Coordenador[]
atividade Atividade[]
tentativasRestantes Int @default(5)
atividade Atividade[]
coordenador Coordenador[]
vinculosProfessor Vinculo[] @relation("ProfessorVinculo")
vinculoComoProfessor Vinculo[] @relation("VinculoComProfessor")
mensagensEnviadas Mensagem[] @relation("MensagensEnviadasProfessor")
mensagensRecebidas Mensagem[] @relation("MensagensRecebidasProfessor")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand All @@ -73,13 +77,13 @@ model Vinculo {
}

model Admin {
id String @id @default(uuid())
name String
email String @unique
password String
imagem String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
id String @id @default(uuid())
name String
email String @unique
password String
imagem String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("admins")
}
Expand Down Expand Up @@ -107,58 +111,60 @@ enum Turno {
}

model Turma {
id String @id @default(uuid())
id String @id @default(uuid())
inicio String
fim String
curso Curso @relation(fields: [cursoId], references: [id])
curso Curso @relation(fields: [cursoId], references: [id])
cursoId String
alunos AlunoTurma[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("turmas")
}

model AlunoTurma {
alunoId String @default(uuid())
turmaId String @default(uuid())
aluno Aluno @relation(fields: [alunoId], references: [id])
turma Turma @relation(fields: [turmaId], references: [id])
alunoId String @default(uuid())
turmaId String @default(uuid())
aluno Aluno @relation(fields: [alunoId], references: [id])
turma Turma @relation(fields: [turmaId], references: [id])
@@id([alunoId, turmaId])
@@map("alunos_turmas")
}

model Extracurricular {
extracurricularId String @id @default(uuid())
alunoId String
aluno Aluno @relation(fields: [alunoId], references: [id])
instituicao String
descricao String
inicio DateTime
fim DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
extracurricularId String @id @default(uuid())
alunoId String
aluno Aluno @relation(fields: [alunoId], references: [id])
instituicao String
descricao String
inicio DateTime
fim DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("extracurriculares")
}

model Empresa {
id String @id @default(uuid())
id String @id @default(uuid())
name String
email String @unique
email String @unique
password String
imagem String?
cnpj String @unique
imagem String?
cnpj String @unique
endereco String?
telefone String?
token String?
patrocinador Boolean @default(false)
validated Boolean @default(false)
patrocinador Boolean @default(false)
validated Boolean @default(false)
tentativasRestantes Int @default(5)
vaga Vaga[]
tentativasRestantes Int @default(5)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
mensagensEnviadas Mensagem[] @relation("MensagensEnviadasEmpresa")
mensagensRecebidas Mensagem[] @relation("MensagensRecebidasEmpresa")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("empresas")
}
Expand Down Expand Up @@ -197,18 +203,20 @@ model Coordenador {
}

model Funcionario {
id String @id @default(uuid())
id String @id @default(uuid())
name String
email String @unique
email String @unique
password String
recoveryPass String?
imagem String?
imagem String?
cargo Cargo
validated Boolean @default(false)
tentativasRestantes Int @default(5)
vaga Vaga[]
validated Boolean @default(false)
tentativasRestantes Int @default(5)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
mensagensEnviadas Mensagem[] @relation("MensagensEnviadasFuncionario")
mensagensRecebidas Mensagem[] @relation("MensagensRecebidasFuncionario")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("funcionarios")
}
Expand All @@ -221,14 +229,39 @@ enum Cargo {
}

model Atividade {
id String @id @default(uuid())
title String
descricao String @db.VarChar(1000)
professor Professor @relation(fields: [professorId], references: [id])
professorId String
imagem String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
id String @id @default(uuid())
title String
descricao String @db.VarChar(1000)
professor Professor @relation(fields: [professorId], references: [id])
professorId String
imagem String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("atividades")
}

model Mensagem {
id String @id @default(uuid())
conteudo String
alunoRemetenteId String?
alunoDestinatarioId String?
professorRemetenteId String?
professorDestinatarioId String?
funcionarioRemetenteId String?
funcionarioDestinatarioId String?
empresaRemetenteId String?
empresaDestinatarioId String?
alunoRemetente Aluno? @relation("MensagensEnviadasAluno", fields: [alunoRemetenteId], references: [id], map: "alunoRemetente_FK")
alunoDestinatario Aluno? @relation("MensagensRecebidasAluno", fields: [alunoDestinatarioId], references: [id], map: "alunoDestinatario_FK")
professorRemetente Professor? @relation("MensagensEnviadasProfessor", fields: [professorRemetenteId], references: [id], map: "professorRemetente_FK")
professorDestinatario Professor? @relation("MensagensRecebidasProfessor", fields: [professorDestinatarioId], references: [id], map: "professorDestinatario_FK")
funcionarioRemetente Funcionario? @relation("MensagensEnviadasFuncionario", fields: [funcionarioRemetenteId], references: [id], map: "funcionarioRemetente_FK")
funcionarioDestinatario Funcionario? @relation("MensagensRecebidasFuncionario", fields: [funcionarioDestinatarioId], references: [id], map: "funcionarioDestinatario_FK")
empresaRemetente Empresa? @relation("MensagensEnviadasEmpresa", fields: [empresaRemetenteId], references: [id], map: "empresaRemetente_FK")
empresaDestinatario Empresa? @relation("MensagensRecebidasEmpresa", fields: [empresaDestinatarioId], references: [id], map: "empresaDestinatario_FK")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("mensagens")
}
23 changes: 22 additions & 1 deletion server/src/modules/controllers/sharedControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import { IgnoreVinculoUseCase } from "../services/shared/IgnoreVinculoUseCase";
import { GetUnlinkedsUseCase } from "../services/shared/GetUnlinkedsUseCase";
import { GetCursosUseCase } from "../services/shared/GetCursosUseCase";
import { GetCurriculoUseCase } from "../services/shared/GetCurriculoUseCase";
import { GetEntidadeDTO, IdentificadorEnum } from "../interfaces/sharedDTOs";
import { GetProfileImageUseCase } from '../services/shared/GetProfileImageUseCase';
import { GetBannerUseCase } from '../services/shared/GetBannerUseCase';
import { CreateMessageUseCase } from "../services/shared/CreateMessageUseCase";

import {
CreateMessageDTO,
GetEntidadeDTO,
IdentificadorEnum
} from "../interfaces/sharedDTOs";

export class CreateVinculoController {
async handle(req: Request, res: Response) {
Expand Down Expand Up @@ -152,6 +158,21 @@ export class GetBannerController {

const result = await getBannerUseCase.execute({ email, identifier });

return res.status(201).json(result);
}
}

export class CreateMessageController {
async handle(req: Request, res: Response) {
const email = req.body.entidade.email;
const { message, sender, recipient, senderIdentifier, recipientIdentifier } = req.body;

console.log

const createMessageUseCase = new CreateMessageUseCase();

const result = await createMessageUseCase.execute({ email, message, sender, recipient, senderIdentifier, recipientIdentifier });

return res.status(201).json(result);
}
}
Loading

0 comments on commit 982e028

Please sign in to comment.