diff --git a/.vscode/settings.json b/.vscode/settings.json index 63a5cd07..6d2567bd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -35,5 +35,10 @@ "unplugin", "Vefago" ], - "cSpell.language": "en,pt-BR" + "cSpell.language": "en,pt-BR", + "rest-client.environmentVariables": { + "$shared": { + "envFile": "/apps/core-rest-api/.env" + } + } } diff --git a/apps/core-rest-api/http/.env.http.example b/apps/core-rest-api/http/.env.http.example new file mode 100644 index 00000000..6098f578 --- /dev/null +++ b/apps/core-rest-api/http/.env.http.example @@ -0,0 +1,38 @@ +BASE_URL='http://localhost:3333/core' +API_KEY='' + +#################### AUTH #################### +AUTH_TOKEN='' + +#################### PSYCHOLOGIST #################### +PSYCHOLOGIST_ID= + +PSYCHOLOGIST_NAME='Joe Doe' +PSYCHOLOGIST_EMAIL='joe_doe@email.com' +PSYCHOLOGIST_PASSWORD='joe-password' + + +#################### CLINIC #################### +CLINIC_ID= + +CLINIC_NAME='New Clinic' +CLINIC_CITY='Fake City' +CLINIC_STATE='Fake State' + +#################### PATIENT #################### +PATIENT_ID= + +PATIENT_NAME='Abigail Doe' +PATIENT_EMAIL='abigail.doe@email.com' +PATIENT_CPF='123.456.789-00' +PATIENT_TELEPHONE='(11) 99999-9999' +PATIENT_PASSWORD='abigail-password' + + + + +#################### APPOINTMENT #################### +APPOINTMENT_ID= + +#################### PATIENT_APPOINTMENT_REGISTRY #################### +PATIENT_APPOINTMENT_REGISTRY_ID= diff --git a/apps/core-rest-api/http/clinic-client.http b/apps/core-rest-api/http/clinic-client.http new file mode 100644 index 00000000..094d2316 --- /dev/null +++ b/apps/core-rest-api/http/clinic-client.http @@ -0,0 +1,36 @@ +@authToken = {{$dotenv AUTH_TOKEN}} +@apiKey = {{$dotenv API_KEY}} +#### + +# @name create_clinic +POST http://localhost:3333/core/clinic/create HTTP/1.1 +Content-Type: application/json +Authorization: Bearer {{authToken}} + +{ + "name": "{{$dotenv CLINIC_NAME}}", + "psychologistId": "{{$dotenv PSYCHOLOGIST_ID}}", + "city": "{{$dotenv CLINIC_CITY}}}}", + "state": "{{$dotenv CLINIC_STATE}}", +} + +#### + +# @name update_clinic + +PATCH http://localhost:3333/core/clinic/8d40bb8d-fd0b-4753-83cf-87bac7b3c6e7/update HTTP/1.1 +Content-Type: application/json +Authorization: Bearer {{authToken}} + +{ + "name": "New Name Clinic" +} + + +#### + +# @name delete_clinic + +DELETE http://localhost:3333/core/clinic/{{$dotenv CLINIC_ID}}/delete HTTP/1.1 +Content-Type: application/json +Authorization: Bearer {{authToken}} diff --git a/apps/core-rest-api/http/initial-setup.client.http b/apps/core-rest-api/http/initial-setup.client.http new file mode 100644 index 00000000..7dbd8fef --- /dev/null +++ b/apps/core-rest-api/http/initial-setup.client.http @@ -0,0 +1,58 @@ +@authToken = {{$dotenv AUTH_TOKEN}} +@apiKey = {{$dotenv API_KEY}} + +##################################### AUTH ##################################### + +# @name loginauthenticate +POST http://localhost:3333/core/psychologist/login HTTP/1.1 +Content-Type: application/json + +{ + "email": "{{$dotenv PSYCHOLOGIST_EMAIL}}", + "password": "{{$dotenv PSYCHOLOGIST_PASSWORD}}" +} +##################################### PSYCHOLOGIST ##################################### + +# @name create_psychologist +POST http://localhost:3333/core/psychologist/create HTTP/1.1 +Content-Type: application/json +api-key:{{apiKey}} + +{ + "name": "{{$dotenv PSYCHOLOGIST_NAME}}", + "email": "{{$dotenv PSYCHOLOGIST_EMAIL}}", + "password": "{{$dotenv PSYCHOLOGIST_PASSWORD}}", + "role": "PSYCHOLOGIST", + "plan": "PREMIUM" +} + +##################################### CLINIC ##################################### + +# @name create_clinic +POST http://localhost:3333/core/clinic/create HTTP/1.1 +Content-Type: application/json +Authorization: Bearer {{authToken}} + +{ + "name": "{{$dotenv CLINIC_NAME}}", + "psychologistId": "{{$dotenv PSYCHOLOGIST_ID}}", + "city": "{{$dotenv CLINIC_CITY}}}}", + "state": "{{$dotenv CLINIC_STATE}}" +} + +##################################### PATIENT ##################################### + +# @name create_patient +POST http://localhost:3333/core/patient/create HTTP/1.1 +Content-Type: application/json +Authorization: Bearer {{authToken}} + +{ + "name": "{{$dotenv PATIENT_NAME}}", + "email": "{{$dotenv PATIENT_EMAIL}}", + "cpf": "{{$dotenv PATIENT_CPF}}", + "telephone": "{{$dotenv PATIENT_TELEPHONE}}", + "psychologistId": "{{$dotenv PSYCHOLOGIST_ID}}", + "clinicId": "{{$dotenv CLINIC_ID}}", + "paymentMethod": "CREDIT_CARD" +} diff --git a/apps/core-rest-api/http/patient-client.http b/apps/core-rest-api/http/patient-client.http new file mode 100644 index 00000000..554129b3 --- /dev/null +++ b/apps/core-rest-api/http/patient-client.http @@ -0,0 +1,19 @@ +@baseUrl = {{$dotenv BASE_URL}} +# @authToken = {{loginauthenticate.response.body.access_token}} +@authToken = {{$dotenv AUTH_TOKEN}} + +### Create a new patient +# @name create_patient +POST http://localhost:3333/core/patient/create HTTP/1.1 +Content-Type: application/json +Authorization: Bearer {{authToken}} + +{ + "name": "{{$dotenv PATIENT_NAME}}", + "email": "{{$dotenv PATIENT_EMAIL}}", + "cpf": "{{$dotenv PATIENT_CPF}}", + "telephone": "{{$dotenv PATIENT_TELEPHONE}}", + "psychologistId": "{{$dotenv PSYCHOLOGIST_ID}}", + "clinicId": "{{$dotenv CLINIC_ID}}", + "paymentMethod": "CREDIT_CARD" +} diff --git a/libs/core-rest-api/adapters/src/controllers/api/use-cases/psychologist/psychologist-client.http b/apps/core-rest-api/http/psychologist-client.http similarity index 52% rename from libs/core-rest-api/adapters/src/controllers/api/use-cases/psychologist/psychologist-client.http rename to apps/core-rest-api/http/psychologist-client.http index 8eea0563..df4a56fa 100644 --- a/libs/core-rest-api/adapters/src/controllers/api/use-cases/psychologist/psychologist-client.http +++ b/apps/core-rest-api/http/psychologist-client.http @@ -1,7 +1,5 @@ -@baseUrl = http://localhost:3333/core -@authToken = {{loginauthenticate.response.body.access_token}} -@psychologist_id = {{loginauthenticate.response.body.user.id}} -@psychologist_email = {{loginauthenticate.response.body.user.email}} +@authToken = {{$dotenv AUTH_TOKEN}} +@apiKey = {{$dotenv API_KEY}} ### Create New User @@ -11,9 +9,9 @@ Content-Type: application/json api-key: api-key { - "name": "Joe Doe", - "email": "joe_doe@email.com", - "password": "joe-password", + "name": "{{$dotenv PSYCHOLOGIST_NAME}}", + "email": "{{$dotenv PSYCHOLOGIST_EMAIL}}", + "password": "{{$dotenv PSYCHOLOGIST_PASSWORD}}", "role": "PSYCHOLOGIST", "plan": "PREMIUM" } @@ -25,14 +23,14 @@ POST http://localhost:3333/core/psychologist/login HTTP/1.1 Content-Type: application/json { - "email": "joe_doe@email.com", - "password": "joe-password" + "email": "{{$dotenv PSYCHOLOGIST_EMAIL}}", + "password": "{{$dotenv PSYCHOLOGIST_PASSWORD}}" } ### Update User # @name update_psychologist -PATCH http://localhost:3333/core/psychologist/{{psychologist_id}}/update HTTP/1.1 +PATCH http://localhost:3333/core/psychologist/{{$dotenv PSYCHOLOGIST_ID}}/update HTTP/1.1 Content-Type: application/json Authorization: Bearer {{authToken}} @@ -40,16 +38,11 @@ Authorization: Bearer {{authToken}} "password": "joe-password-updated" } -### Test Route +### Delete User + # @name delete_psychologist -DELETE http://localhost:3333/core/psychologist/{{psychologist_email}}/delete HTTP/1.1 +DELETE http://localhost:3333/core/psychologist/{{$dotenv PSYCHOLOGIST_EMAIL}}/delete HTTP/1.1 # DELETE http://localhost:3333/core/psychologist/wrong_email@gmail.com/delete HTTP/1.1 # DELETE http://localhost:3333/core/psychologist/invalid_email/delete HTTP/1.1 Content-Type: application/json Authorization: Bearer {{authToken}} - -### Test Route -# @name me -GET http://localhost:3333/core/psychologist/me HTTP/1.1 -Content-Type: application/json -Authorization: Bearer {{authToken}} diff --git a/libs/core-rest-api/adapters/project.json b/libs/core-rest-api/adapters/project.json index e8d97426..e14acc12 100644 --- a/libs/core-rest-api/adapters/project.json +++ b/libs/core-rest-api/adapters/project.json @@ -8,19 +8,6 @@ "executor": "@nx/eslint:lint", "outputs": ["{options.outputFile}"] }, - "test": { - "executor": "@nx/vite:test", - "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], - "options": { - "passWithNoTests": true - }, - "configurations": { - "ci": { - "ci": true, - "codeCoverage": true - } - } - }, "e2e": { "executor": "@nx/vite:test", "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], diff --git a/libs/core-rest-api/adapters/src/controllers/api/api.module.ts b/libs/core-rest-api/adapters/src/controllers/api/api.module.ts index 5f69048d..09b5a291 100644 --- a/libs/core-rest-api/adapters/src/controllers/api/api.module.ts +++ b/libs/core-rest-api/adapters/src/controllers/api/api.module.ts @@ -17,6 +17,8 @@ import { DeleteClinicController } from './use-cases/clinic/delete-clinic/delete- import { NestjsDeleteClinicService } from './use-cases/clinic/delete-clinic/nestjs-delete-clinic.service'; import { NestjsUpdateClinicService } from './use-cases/clinic/update-clinic/nestjs-update-clinic.service'; import { UpdateClinicController } from './use-cases/clinic/update-clinic/update-clinic.controller'; +import { CreatePatientController } from './use-cases/patient/create-patient/create-patient.controller'; +import { NestjsCreatePatientService } from './use-cases/patient/create-patient/nestjs-create-patient.service'; import { AuthenticatePsychologistController } from './use-cases/psychologist/authenticate-psychologist/authenticate-psychologist.controller'; import { NestjsAuthenticatePsychologistService } from './use-cases/psychologist/authenticate-psychologist/nestjs-authenticate-psychologist.service'; import { CreatePsychologistController } from './use-cases/psychologist/create-psychologist/create-psychologist.controller'; @@ -43,7 +45,8 @@ import { NestjsUpdatePsychologistService } from './use-cases/psychologist/update DeletePsychologistController, CreateClinicController, UpdateClinicController, - DeleteClinicController + DeleteClinicController, + CreatePatientController, ], providers: [ BcryptHasherService, @@ -54,7 +57,8 @@ import { NestjsUpdatePsychologistService } from './use-cases/psychologist/update NestjsDeletePsychologistService, NestjsCreateClinicService, NestjsUpdateClinicService, - NestjsDeleteClinicService + NestjsDeleteClinicService, + NestjsCreatePatientService, ], }) export class ApiModule {} diff --git a/libs/core-rest-api/adapters/src/controllers/api/shared/utils/e2e-tests-initial-setup.ts b/libs/core-rest-api/adapters/src/controllers/api/shared/utils/e2e-tests-initial-setup.ts index 3cebc485..a2411d97 100644 --- a/libs/core-rest-api/adapters/src/controllers/api/shared/utils/e2e-tests-initial-setup.ts +++ b/libs/core-rest-api/adapters/src/controllers/api/shared/utils/e2e-tests-initial-setup.ts @@ -3,23 +3,29 @@ import { faker } from '@faker-js/faker'; import { INestApplication, ValidationPipe } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { Test, TestingModule } from '@nestjs/testing'; -import { ClinicFactory } from '../../../../../tests/factories/make-clinic'; -import { PsychologistFactory } from '../../../../../tests/factories/make-psychologist'; + import { PostgreSqlPrismaOrmService } from '../../../../database/infra/prisma/prisma.service'; import { DatabaseRepositoriesModule } from '../../../../database/repositories/repositories.module'; import { ApiModule } from '../../api.module'; +import { ClinicFactory } from '../../../../../tests/factories/make-clinic'; +import { PatientFactory } from '../../../../../tests/factories/make-patient'; +import { PsychologistFactory } from '../../../../../tests/factories/make-psychologist'; + export async function setupE2ETest() { const moduleRef: TestingModule = await Test.createTestingModule({ imports: [ApiModule, DatabaseRepositoriesModule], - providers: [PsychologistFactory, ClinicFactory], + providers: [PsychologistFactory, ClinicFactory, PatientFactory], }).compile(); const app: INestApplication = moduleRef.createNestApplication(); const prisma: PostgreSqlPrismaOrmService = moduleRef.get(PostgreSqlPrismaOrmService); + const clinicFactory: ClinicFactory = moduleRef.get(ClinicFactory); const psychologistFactory: PsychologistFactory = moduleRef.get(PsychologistFactory); + const patientFactory: PatientFactory = moduleRef.get(PatientFactory); + const jwt: JwtService = moduleRef.get(JwtService); // Necessary to validate DTO route params in the controller @@ -55,18 +61,26 @@ export async function setupE2ETest() { state: faker.location.city(), }); + // Creating a patient to use in tests + const patient = await patientFactory.makePrismaPatient({ + psychologistId: psychologist.id, + clinicId: clinic.id, + }); + return { prisma, app, psychologistFactory, - clinicFactory, - jwt, + psychologist, id, + hashedPassword, + password, + jwt, access_token, invalid_access_token, - psychologist, + clinicFactory, clinic, - hashedPassword, - password, + patientFactory, + patient, }; } diff --git a/libs/core-rest-api/adapters/src/controllers/api/use-cases/clinic/clinic-client.http b/libs/core-rest-api/adapters/src/controllers/api/use-cases/clinic/clinic-client.http deleted file mode 100644 index 5e7ff6f2..00000000 --- a/libs/core-rest-api/adapters/src/controllers/api/use-cases/clinic/clinic-client.http +++ /dev/null @@ -1,48 +0,0 @@ -@baseUrl = http://localhost:3333/core -@authToken = {{loginauthenticate.response.body.access_token}} -@psychologist_id = {{loginauthenticate.response.body.user.id}} - -# @name loginauthenticate -POST http://localhost:3333/core/psychologist/login HTTP/1.1 -Content-Type: application/json - -{ - "email": "joe_doe@email.com", - "password": "joe-password" -} - -#### - -# @name create_clinic - -POST http://localhost:3333/core/clinic/create HTTP/1.1 -Content-Type: application/json -Authorization: Bearer {{authToken}} - -{ - "name": "New Clinic", - "psychologistId": "{{psychologist_id}}", - "city": "Fake City", - "state": "Fake State" -} - -#### - -# @name update_clinic - -PATCH http://localhost:3333/core/clinic/8d40bb8d-fd0b-4753-83cf-87bac7b3c6e7/update HTTP/1.1 -Content-Type: application/json -Authorization: Bearer {{authToken}} - -{ - "name": "New Name Clinic" -} - - -#### - -# @name delete_clinic - -DELETE http://localhost:3333/core/clinic/159b4134-9d2a-4198-98c3-ac031eb31998/delete HTTP/1.1 -Content-Type: application/json -Authorization: Bearer {{authToken}} diff --git a/libs/core-rest-api/adapters/src/controllers/api/use-cases/clinic/delete-clinic/delete-clinic.e2e-spec.ts b/libs/core-rest-api/adapters/src/controllers/api/use-cases/clinic/delete-clinic/delete-clinic.e2e-spec.ts index d9a4f9f2..a0af0b6e 100644 --- a/libs/core-rest-api/adapters/src/controllers/api/use-cases/clinic/delete-clinic/delete-clinic.e2e-spec.ts +++ b/libs/core-rest-api/adapters/src/controllers/api/use-cases/clinic/delete-clinic/delete-clinic.e2e-spec.ts @@ -25,7 +25,7 @@ describe('[E2E] - Delete Clinic', () => { it('[DELETE] - Should return an error when trying to delete a clinic without access_token', async () => { const response = await request(app.getHttpServer()).delete( - `/clinic/${clinic.id}/delete` + `/clinic/${clinic.id}/delete`, ); expect(response.status).toBe(401); @@ -63,13 +63,15 @@ describe('[E2E] - Delete Clinic', () => { expect.objectContaining({ clinic: expect.objectContaining({ name: expect.any(String) }), deletedAt: expect.any(String), - }) + }), ); const deletedClinic = await prisma['clinic'].findUnique({ where: { id: clinic.id }, }); + console.log('DELETED CLINIC ---->', deletedClinic); + expect(deletedClinic).toBeNull(); }); }); diff --git a/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/create-patient.controller.ts b/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/create-patient.controller.ts new file mode 100644 index 00000000..03df8366 --- /dev/null +++ b/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/create-patient.controller.ts @@ -0,0 +1,31 @@ +import { Body, Controller, Post } from '@nestjs/common'; +import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger'; +import { postMethodDocs } from './docs'; + +import { GlobalAppHttpException } from '@clinicControl/core-rest-api/core/src/shared/errors/globalAppHttpException'; + +import { CreatePatientDto } from '@clinicControl/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient-dto'; +import { NestjsCreatePatientService } from './nestjs-create-patient.service'; + +@ApiTags('patient') +@ApiBearerAuth() +@Controller({ + path: 'patient', +}) +export class CreatePatientController { + constructor(private createPatientService: NestjsCreatePatientService) {} + + @Post('create') + @ApiOperation(postMethodDocs) + async execute(@Body() createPatientDto: CreatePatientDto) { + try { + await this.createPatientService.execute(createPatientDto); + + return { + message: 'Patient created successfully', + }; + } catch (error: unknown) { + throw new GlobalAppHttpException(error); + } + } +} diff --git a/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/create-patient.e2e-spec.ts b/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/create-patient.e2e-spec.ts new file mode 100644 index 00000000..0d2071e8 --- /dev/null +++ b/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/create-patient.e2e-spec.ts @@ -0,0 +1,93 @@ +import request from 'supertest'; + +import { PatientEntity } from '@clinicControl/core-rest-api/core/src/domains/patient/entities/patient/entity'; +import { CreatePatientDto } from '@clinicControl/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient-dto'; +import { INestApplication } from '@nestjs/common'; +import { makePatient } from '../../../../../../tests/factories/make-patient'; +import { PostgreSqlPrismaOrmService } from '../../../../../database/infra/prisma/prisma.service'; +import { setupE2ETest } from '../../../shared/utils/e2e-tests-initial-setup'; + +describe('[E2E] - Create New Patient', () => { + let app: INestApplication; + let prisma: PostgreSqlPrismaOrmService; + + let access_token: string; + + let psychologistId: string; + let clinicId: string; + + let patient: PatientEntity; + + beforeAll(async () => { + const setup = await setupE2ETest(); + + app = setup.app; + prisma = setup.prisma; + + access_token = setup.access_token; + + clinicId = setup.clinic.id; + psychologistId = setup.psychologist.id; + + patient = setup.patient; + }); + + it('[POST] - Should successfully create a new patient account', async () => { + const newPatient: CreatePatientDto = makePatient({ + email: 'new_patient@email.com', + psychologistId, + clinicId, + }); + + const response = await request(app.getHttpServer()) + .post('/patient/create') + .set('Authorization', `Bearer ${access_token}`) + .send(newPatient); + + const patientOnDatabase = await prisma.patient.findUnique({ + where: { + email: newPatient.email, + }, + }); + + expect(response.statusCode).toBe(201); + expect(response.body.message).toBe('Patient created successfully'); + expect(patientOnDatabase).toBeTruthy(); + }); + + it('[POST] - Should return an error when trying to create a patient that already exists', async () => { + const response = await request(app.getHttpServer()) + .post('/patient/create') + .set('Authorization', `Bearer ${access_token}`) + .send(patient); + + expect(response.statusCode).toBe(409); + expect(response.body.message).toBe('patient already exists'); + }); + + it('[POST] - Should return an error when trying to create a new patient without token', async () => { + const response = await request(app.getHttpServer()) + .post('/patient/create') + .send(patient); + + expect(response.statusCode).toBe(401); + expect(response.body.message).toBe('Invalid JWT token'); + }); + + it('[POST] - Should return an error when trying to create a new patient without body request', async () => { + const response = await request(app.getHttpServer()) + .post('/patient/create') + .set('Authorization', `Bearer ${access_token}`); + + expect(response.statusCode).toBe(400); + expect(response.body.message).deep.equals([ + 'name must be a string', + 'email must be a string', + 'cpf must be a string', + 'telephone must be a phone number', + 'paymentMethod must be one of the following values: CREDIT_CARD, DEBIT_CARD, PIX, MONEY, HEALTH_INSURANCE, OTHER', + 'psychologistId must be a string', + 'clinicId must be a string', + ]); + }); +}); diff --git a/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/docs.ts b/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/docs.ts new file mode 100644 index 00000000..e7a54e22 --- /dev/null +++ b/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/docs.ts @@ -0,0 +1,17 @@ +import { OperationObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface'; + +const description = ` +--- +\`Experimental\` +--- + +### Create a new Patient in the system + +This endpoint help you to create a new patient. +You must at least provide one of the following body parameters +`; + +export const postMethodDocs: Partial = { + summary: 'Create a new patient', + description, +}; diff --git a/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/nestjs-create-patient.service.ts b/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/nestjs-create-patient.service.ts new file mode 100644 index 00000000..e4a0dd95 --- /dev/null +++ b/libs/core-rest-api/adapters/src/controllers/api/use-cases/patient/create-patient/nestjs-create-patient.service.ts @@ -0,0 +1,11 @@ +import { Injectable } from '@nestjs/common'; + +import { PatientDatabaseRepository } from '@clinicControl/core-rest-api/core/src/domains/patient/repositories/database-repository'; +import { CreatePatientService } from '@clinicControl/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient.service'; + +@Injectable() +export class NestjsCreatePatientService extends CreatePatientService { + constructor(patientDatabaseRepository: PatientDatabaseRepository) { + super(patientDatabaseRepository); + } +} diff --git a/libs/core-rest-api/adapters/src/database/infra/prisma/migrations/20231219023557_updated_clinic_psychologist_patient_on_delete/migration.sql b/libs/core-rest-api/adapters/src/database/infra/prisma/migrations/20231219023557_updated_clinic_psychologist_patient_on_delete/migration.sql new file mode 100644 index 00000000..38837e2d --- /dev/null +++ b/libs/core-rest-api/adapters/src/database/infra/prisma/migrations/20231219023557_updated_clinic_psychologist_patient_on_delete/migration.sql @@ -0,0 +1,23 @@ +-- DropForeignKey +ALTER TABLE "patient" DROP CONSTRAINT "patient_clinic_id_fkey"; + +-- DropForeignKey +ALTER TABLE "patient" DROP CONSTRAINT "patient_psychologist_id_fkey"; + +-- DropForeignKey +ALTER TABLE "patient_appointments_registry" DROP CONSTRAINT "patient_appointments_registry_patient_id_fkey"; + +-- DropForeignKey +ALTER TABLE "patient_appointments_registry" DROP CONSTRAINT "patient_appointments_registry_psychologist_id_fkey"; + +-- AddForeignKey +ALTER TABLE "patient" ADD CONSTRAINT "patient_psychologist_id_fkey" FOREIGN KEY ("psychologist_id") REFERENCES "psychologist"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "patient" ADD CONSTRAINT "patient_clinic_id_fkey" FOREIGN KEY ("clinic_id") REFERENCES "clinic"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "patient_appointments_registry" ADD CONSTRAINT "patient_appointments_registry_patient_id_fkey" FOREIGN KEY ("patient_id") REFERENCES "patient"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "patient_appointments_registry" ADD CONSTRAINT "patient_appointments_registry_psychologist_id_fkey" FOREIGN KEY ("psychologist_id") REFERENCES "psychologist"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/libs/core-rest-api/adapters/src/database/infra/prisma/postgresql.schema.prisma b/libs/core-rest-api/adapters/src/database/infra/prisma/postgresql.schema.prisma index e7a44793..063edc50 100644 --- a/libs/core-rest-api/adapters/src/database/infra/prisma/postgresql.schema.prisma +++ b/libs/core-rest-api/adapters/src/database/infra/prisma/postgresql.schema.prisma @@ -81,9 +81,9 @@ model Patient { patientAppointmentsRegistry PatientAppointmentsRegistry[] psychologistId String @map("psychologist_id") - psychologist Psychologist @relation(fields: [psychologistId], references: [id]) + psychologist Psychologist @relation(fields: [psychologistId], references: [id], onDelete: Cascade) clinicId String @map("clinic_id") - clinic Clinic @relation(fields: [clinicId], references: [id]) + clinic Clinic @relation(fields: [clinicId], references: [id], onDelete: Cascade) @@map("patient") } @@ -120,9 +120,9 @@ model PatientAppointmentsRegistry { registry Json @db.Json patientId String @map("patient_id") - patient Patient @relation(fields: [patientId], references: [id]) + patient Patient @relation(fields: [patientId], references: [id], onDelete: Cascade) psychologistId String @map("psychologist_id") - psychologist Psychologist @relation(fields: [psychologistId], references: [id]) + psychologist Psychologist @relation(fields: [psychologistId], references: [id], onDelete: Cascade) @@map("patient_appointments_registry") } diff --git a/libs/core-rest-api/adapters/src/database/mappers/postgresql-prisma-patient-mapper.ts b/libs/core-rest-api/adapters/src/database/mappers/postgresql-prisma-patient-mapper.ts new file mode 100644 index 00000000..3a4df6bd --- /dev/null +++ b/libs/core-rest-api/adapters/src/database/mappers/postgresql-prisma-patient-mapper.ts @@ -0,0 +1,40 @@ +import { + Prisma, + Patient as PrismaPatientDto, + PaymentMethod as PrismaPaymentMethod, +} from '@prisma/client'; + +import { PatientEntity } from '@clinicControl/core-rest-api/core/src/domains/patient/entities/patient/entity'; +import { CreatePatientDto } from '@clinicControl/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient-dto'; +import { UpdatePatientDto } from '@clinicControl/core-rest-api/core/src/domains/patient/use-cases/update-patient/update-patient-dto'; +import { PaymentMethod } from '@clinicControl/core-rest-api/core/src/shared/interfaces/payments'; + +export class PostgresqlPrismaPatientMapper { + static toDomain(raw: PrismaPatientDto): PatientEntity { + return new PatientEntity({ + ...raw, + paymentMethod: raw.paymentMethod as unknown as PaymentMethod, + }); + } + + static toPrismaCreate(raw: CreatePatientDto): Prisma.PatientCreateArgs { + return { + data: { + ...raw, + paymentMethod: raw.paymentMethod as unknown as PrismaPaymentMethod, + }, + }; + } + + static toPrismaUpdate(raw: UpdatePatientDto): Prisma.PatientUpdateArgs { + return { + data: { + ...raw, + paymentMethod: raw.paymentMethod as unknown as PrismaPaymentMethod, + }, + where: { + id: raw.id, + }, + }; + } +} diff --git a/libs/core-rest-api/adapters/src/database/repositories/patient/postgres-prisma-orm-patient-repository.ts b/libs/core-rest-api/adapters/src/database/repositories/patient/postgres-prisma-orm-patient-repository.ts new file mode 100644 index 00000000..80864d41 --- /dev/null +++ b/libs/core-rest-api/adapters/src/database/repositories/patient/postgres-prisma-orm-patient-repository.ts @@ -0,0 +1,93 @@ +import { PATIENT_ERROR_MESSAGES } from '@clinicControl/core-rest-api/core/src/shared/errors/error-messages'; +import { ConflictException, Injectable } from '@nestjs/common'; + +import { PatientEntity } from '@clinicControl/core-rest-api/core/src/domains/patient/entities/patient/entity'; +import { PatientDatabaseRepository } from '@clinicControl/core-rest-api/core/src/domains/patient/repositories/database-repository'; +import { CreatePatientDto } from '@clinicControl/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient-dto'; +import { UpdatePatientDto } from '@clinicControl/core-rest-api/core/src/domains/patient/use-cases/update-patient/update-patient-dto'; +import { PostgreSqlPrismaOrmService } from '../../infra/prisma/prisma.service'; +import { PostgresqlPrismaPatientMapper } from '../../mappers/postgresql-prisma-patient-mapper'; + +@Injectable() +export class PostgresqlPrismaOrmPatientRepository implements PatientDatabaseRepository { + constructor(private postgresqlPrismaOrmService: PostgreSqlPrismaOrmService) {} + + async createPatient(patient: CreatePatientDto): Promise { + const isPatientExists = await this.findPatientByEmail(patient.email); + + if (isPatientExists) { + throw new ConflictException(PATIENT_ERROR_MESSAGES['CONFLICTING_CREDENTIALS']); + } + + const toPrismaEntity = PostgresqlPrismaPatientMapper.toPrismaCreate({ + ...patient, + }); + + const newPatient = + await this.postgresqlPrismaOrmService['patient'].create(toPrismaEntity); + + return PostgresqlPrismaPatientMapper.toDomain(newPatient); + } + + async findPatientByEmail(email: string): Promise { + const patient = await this.postgresqlPrismaOrmService['patient'].findUnique({ + where: { + email: email, + }, + }); + + if (!patient) { + return null; + } + + return PostgresqlPrismaPatientMapper.toDomain(patient); + } + + async findPatientById(id: string): Promise { + const patient = await this.postgresqlPrismaOrmService['patient'].findUnique({ + where: { + id: id, + }, + }); + + if (!patient) { + return null; + } + + return PostgresqlPrismaPatientMapper.toDomain(patient); + } + + async getPatients(): Promise { + const patients = await this.postgresqlPrismaOrmService['patient'].findMany(); + + return patients.map((patient) => PostgresqlPrismaPatientMapper.toDomain(patient)); + } + + async updatePatient(newPatientInfo: UpdatePatientDto): Promise { + const oldPatientInfo = await this.findPatientById(newPatientInfo.id); + + if (!oldPatientInfo) { + throw new ConflictException(PATIENT_ERROR_MESSAGES['PATIENT_NOT_FOUND']); + } + + const toPrismaEntity = PostgresqlPrismaPatientMapper.toPrismaUpdate({ + ...newPatientInfo, + }); + + await this.postgresqlPrismaOrmService['patient'].update(toPrismaEntity); + } + + async deletePatient(email: string): Promise { + const isPatientExists = await this.findPatientByEmail(email); + + if (!isPatientExists) { + throw new ConflictException(PATIENT_ERROR_MESSAGES['PATIENT_NOT_FOUND']); + } + + await this.postgresqlPrismaOrmService['patient'].delete({ + where: { + email: email, + }, + }); + } +} diff --git a/libs/core-rest-api/adapters/src/database/repositories/repositories.module.ts b/libs/core-rest-api/adapters/src/database/repositories/repositories.module.ts index 22e4df23..6983cd89 100644 --- a/libs/core-rest-api/adapters/src/database/repositories/repositories.module.ts +++ b/libs/core-rest-api/adapters/src/database/repositories/repositories.module.ts @@ -1,8 +1,12 @@ +import { Module } from '@nestjs/common'; + import { ClinicDatabaseRepository } from '@clinicControl/core-rest-api/core/src/domains/clinic/repositories/database-repository'; +import { PatientDatabaseRepository } from '@clinicControl/core-rest-api/core/src/domains/patient/repositories/database-repository'; import { PsychologistDatabaseRepository } from '@clinicControl/core-rest-api/core/src/domains/psychologist/repositories/database-repository'; -import { Module } from '@nestjs/common'; + import { PostgreSqlPrismaOrmService } from '../infra/prisma/prisma.service'; import { PostgresqlPrismaOrmClinicRepository } from './clinic/postgres-prisma-orm-clinic-repository'; +import { PostgresqlPrismaOrmPatientRepository } from './patient/postgres-prisma-orm-patient-repository'; import { PostgresqlPrismaOrmPsychologistRepository } from './psychologist/postgresql-prisma-orm-psychologist-repository'; @Module({ @@ -18,6 +22,10 @@ import { PostgresqlPrismaOrmPsychologistRepository } from './psychologist/postgr provide: ClinicDatabaseRepository, useClass: PostgresqlPrismaOrmClinicRepository, }, + { + provide: PatientDatabaseRepository, + useClass: PostgresqlPrismaOrmPatientRepository, + }, ], exports: [ PostgreSqlPrismaOrmService, @@ -29,6 +37,10 @@ import { PostgresqlPrismaOrmPsychologistRepository } from './psychologist/postgr provide: ClinicDatabaseRepository, useClass: PostgresqlPrismaOrmClinicRepository, }, + { + provide: PatientDatabaseRepository, + useClass: PostgresqlPrismaOrmPatientRepository, + }, ], }) export class DatabaseRepositoriesModule {} diff --git a/libs/core-rest-api/adapters/tests/factories/make-patient.ts b/libs/core-rest-api/adapters/tests/factories/make-patient.ts new file mode 100644 index 00000000..3e7c1ec2 --- /dev/null +++ b/libs/core-rest-api/adapters/tests/factories/make-patient.ts @@ -0,0 +1,40 @@ +import { fakerPT_BR as faker } from '@faker-js/faker'; +import { Injectable } from '@nestjs/common'; + +import { PatientEntity } from '@clinicControl/core-rest-api/core/src/domains/patient/entities/patient/entity'; +import { CreatePatientDto } from '@clinicControl/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient-dto'; +import { PaymentMethod } from '@clinicControl/core-rest-api/core/src/shared/interfaces/payments'; +import { PostgreSqlPrismaOrmService } from '../../src/database/infra/prisma/prisma.service'; +import { PostgresqlPrismaPatientMapper } from '../../src/database/mappers/postgresql-prisma-patient-mapper'; + +export function makePatient(override: Partial = {}): PatientEntity { + const newPatient = new PatientEntity({ + name: faker.person.fullName(), + email: faker.internet.email(), + cpf: faker.number.int({ min: 0, max: 10000000000 }).toString(), + telephone: '+55 11 911111111', + paymentMethod: PaymentMethod.CREDIT_CARD, + psychologistId: faker.string.uuid(), + clinicId: faker.string.uuid(), + ...override, + }); + + return newPatient; +} + +@Injectable() +export class PatientFactory { + constructor(private postgreSqlPrismaOrmService: PostgreSqlPrismaOrmService) {} + + async makePrismaPatient( + patient: Partial = {}, + ): Promise { + const newPrismaPatient = makePatient(patient); + + await this.postgreSqlPrismaOrmService['patient'].create( + PostgresqlPrismaPatientMapper.toPrismaCreate(newPrismaPatient), + ); + + return newPrismaPatient; + } +} diff --git a/libs/core-rest-api/adapters/vite.config.ts b/libs/core-rest-api/adapters/vite.config.ts index a9e5c3b1..d11b0b9a 100644 --- a/libs/core-rest-api/adapters/vite.config.ts +++ b/libs/core-rest-api/adapters/vite.config.ts @@ -13,7 +13,7 @@ export default defineConfig({ swc.vite({ module: { type: 'es6' }, }), - tsconfigPaths() + tsconfigPaths(), ], // Uncomment this if you are using workers. @@ -28,5 +28,6 @@ export default defineConfig({ dir: '../../../node_modules/.vitest', }, include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + reporters: ['default'], }, }); diff --git a/libs/core-rest-api/adapters/vitest.config.e2e.ts b/libs/core-rest-api/adapters/vitest.config.e2e.ts index 62fc7c15..f1958f21 100644 --- a/libs/core-rest-api/adapters/vitest.config.e2e.ts +++ b/libs/core-rest-api/adapters/vitest.config.e2e.ts @@ -10,7 +10,7 @@ export default defineConfig({ swc.vite({ module: { type: 'es6' }, }), - tsconfigPaths() + tsconfigPaths(), ], test: { globals: true, @@ -18,5 +18,6 @@ export default defineConfig({ root: './libs/core-rest-api/adapters/', setupFiles: ['./tests/setup-e2e.ts'], environment: 'node', + reporters: ['default'], }, }); diff --git a/libs/core-rest-api/core/src/domains/patient/entities/patient/dto.ts b/libs/core-rest-api/core/src/domains/patient/entities/patient/dto.ts index 98f3e55f..a03506fb 100644 --- a/libs/core-rest-api/core/src/domains/patient/entities/patient/dto.ts +++ b/libs/core-rest-api/core/src/domains/patient/entities/patient/dto.ts @@ -1,10 +1,4 @@ -import { - IsDate, - IsEnum, - IsMobilePhone, - IsOptional, - IsString, -} from 'class-validator'; +import { IsDate, IsEnum, IsMobilePhone, IsOptional, IsString } from 'class-validator'; import { PaymentMethod } from '../../../../shared/interfaces/payments'; export class PatientDto { @@ -18,10 +12,10 @@ export class PatientDto { email!: string; @IsString() - CPF!: string; + cpf!: string; @IsMobilePhone('pt-BR') - phone!: string; + telephone!: string; @IsEnum(PaymentMethod) paymentMethod!: PaymentMethod; diff --git a/libs/core-rest-api/core/src/domains/patient/entities/patient/entity.ts b/libs/core-rest-api/core/src/domains/patient/entities/patient/entity.ts index 69a15007..24e6531f 100644 --- a/libs/core-rest-api/core/src/domains/patient/entities/patient/entity.ts +++ b/libs/core-rest-api/core/src/domains/patient/entities/patient/entity.ts @@ -33,19 +33,19 @@ export class PatientEntity extends PatientDto { } public get getCPF(): string { - return this.CPF; + return this.cpf; } public set setCPF(CPF: string) { - this.CPF = CPF; + this.cpf = CPF; } public get getPhone(): string { - return this.phone; + return this.telephone; } - public set setPhone(phone: string) { - this.phone = phone; + public set setPhone(telephone: string) { + this.telephone = telephone; } public get getPaymentMethod(): PaymentMethod { diff --git a/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient-dto.ts b/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient-dto.ts index ee895926..235a555c 100644 --- a/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient-dto.ts +++ b/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient-dto.ts @@ -9,10 +9,10 @@ export class CreatePatientDto { email!: string; @IsString() - CPF!: string; + cpf!: string; @IsMobilePhone('pt-BR') - phone!: string; + telephone!: string; @IsEnum(PaymentMethod) paymentMethod!: PaymentMethod; diff --git a/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient.service.ts b/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient.service.ts index 6d33e1c5..f3f1a567 100644 --- a/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient.service.ts +++ b/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient.service.ts @@ -11,32 +11,22 @@ import { CreatePatientDto } from './create-patient-dto'; export class CreatePatientService { constructor(private patientDatabaseRepository: PatientDatabaseRepository) {} - async execute( - createPatientDto: ICreatePatientServiceProps - ): Promise { + async execute(createPatientDto: ICreatePatientServiceProps): Promise { // Validate - const createPatientDtoInstance = plainToInstance( - CreatePatientDto, - createPatientDto - ); + const createPatientDtoInstance = plainToInstance(CreatePatientDto, createPatientDto); await applicationValidateOrReject(createPatientDtoInstance); - const isPatientExists = - await this.patientDatabaseRepository.findPatientByEmail( - createPatientDto.email - ); + const isPatientExists = await this.patientDatabaseRepository.findPatientByEmail( + createPatientDto.email, + ); if (isPatientExists) { - throw new ConflictException( - PATIENT_ERROR_MESSAGES['CONFLICTING_CREDENTIALS'] - ); + throw new ConflictException(PATIENT_ERROR_MESSAGES['CONFLICTING_CREDENTIALS']); } // Create - const patient = await this.patientDatabaseRepository.createPatient( - createPatientDto - ); + const patient = await this.patientDatabaseRepository.createPatient(createPatientDto); return patient; } diff --git a/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient.spec.ts b/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient.spec.ts index b16bdc6d..dd53b46b 100644 --- a/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient.spec.ts +++ b/libs/core-rest-api/core/src/domains/patient/use-cases/create-patient/create-patient.spec.ts @@ -11,8 +11,8 @@ describe('[patient] Create Patient Service', () => { const fakePatient: CreatePatientDto = { name: faker.person.fullName(), email: faker.internet.email(), - CPF: faker.number.int({ min: 0, max: 10000000000 }).toString(), - phone: '+55 11 911111111', + cpf: faker.number.int({ min: 0, max: 10000000000 }).toString(), + telephone: '+55 11 911111111', paymentMethod: PaymentMethod.CREDIT_CARD, psychologistId: randomUUID(), clinicId: randomUUID(), @@ -29,8 +29,9 @@ describe('[patient] Create Patient Service', () => { it('should create a new patient', async () => { const patient = await service.execute(fakePatient); - const patientDatabaseRepository = - await databaseRepository.findPatientByEmail(patient.email); + const patientDatabaseRepository = await databaseRepository.findPatientByEmail( + patient.email, + ); expect(patientDatabaseRepository?.email).toEqual(patient.email); expect(patient.email).toEqual(fakePatient.email); }); @@ -38,8 +39,6 @@ describe('[patient] Create Patient Service', () => { it('should throw conflict exception if email already exists', async () => { await service.execute(fakePatient); - await expect(service.execute(fakePatient)).rejects.toThrow( - ConflictException - ); + await expect(service.execute(fakePatient)).rejects.toThrow(ConflictException); }); }); diff --git a/libs/core-rest-api/core/src/domains/patient/use-cases/delete-patient/delete-patient.spec.ts b/libs/core-rest-api/core/src/domains/patient/use-cases/delete-patient/delete-patient.spec.ts index 7452b01d..5f3e7b16 100644 --- a/libs/core-rest-api/core/src/domains/patient/use-cases/delete-patient/delete-patient.spec.ts +++ b/libs/core-rest-api/core/src/domains/patient/use-cases/delete-patient/delete-patient.spec.ts @@ -10,8 +10,8 @@ describe('[patient] Delete Patient Service', () => { const fakePatient = { name: faker.person.fullName(), email: faker.internet.email(), - CPF: faker.number.int({ min: 0, max: 10000000000 }).toString(), - phone: '+55 11 911111111', + cpf: faker.number.int({ min: 0, max: 10000000000 }).toString(), + telephone: '+55 11 911111111', paymentMethod: PaymentMethod.CREDIT_CARD, psychologistId: randomUUID(), clinicId: randomUUID(), @@ -36,8 +36,6 @@ describe('[patient] Delete Patient Service', () => { }); it('should throw conflict exception if patient do not exist', async () => { - await expect(service.execute(fakePatient.email)).rejects.toThrow( - ConflictException - ); + await expect(service.execute(fakePatient.email)).rejects.toThrow(ConflictException); }); }); diff --git a/libs/core-rest-api/core/src/domains/patient/use-cases/update-patient/update-patient-dto.ts b/libs/core-rest-api/core/src/domains/patient/use-cases/update-patient/update-patient-dto.ts index 7e7c4f37..0cf09d8e 100644 --- a/libs/core-rest-api/core/src/domains/patient/use-cases/update-patient/update-patient-dto.ts +++ b/libs/core-rest-api/core/src/domains/patient/use-cases/update-patient/update-patient-dto.ts @@ -15,11 +15,11 @@ export class UpdatePatientDto { @IsOptional() @IsString() - CPF?: string; + cpf?: string; @IsOptional() @IsMobilePhone('pt-BR') - phone?: string; + telephone?: string; @IsOptional() @IsEnum(PaymentMethod) diff --git a/libs/core-rest-api/core/src/domains/patient/use-cases/update-patient/update-patient.spec.ts b/libs/core-rest-api/core/src/domains/patient/use-cases/update-patient/update-patient.spec.ts index 8aef450f..ba8e6597 100644 --- a/libs/core-rest-api/core/src/domains/patient/use-cases/update-patient/update-patient.spec.ts +++ b/libs/core-rest-api/core/src/domains/patient/use-cases/update-patient/update-patient.spec.ts @@ -13,8 +13,8 @@ describe('[patient] Update Patient Service', () => { const fakePatient: CreatePatientDto = { name: faker.person.fullName(), email: faker.internet.email(), - CPF: faker.number.int({ min: 0, max: 10000000000 }).toString(), - phone: '+55 11 911111111', + cpf: faker.number.int({ min: 0, max: 10000000000 }).toString(), + telephone: '+55 11 911111111', paymentMethod: PaymentMethod.CREDIT_CARD, psychologistId: randomUUID(), clinicId: randomUUID(), @@ -35,14 +35,12 @@ describe('[patient] Update Patient Service', () => { id: createPatient.id, email: faker.internet.email(), paymentMethod: PaymentMethod.PIX, - phone: '+55 11 911112111', + telephone: '+55 11 911112111', }; await service.execute(newPatientInfos); - const findPatient = await databaseRepository.findPatientById( - createPatient.id - ); + const findPatient = await databaseRepository.findPatientById(createPatient.id); expect(findPatient).toEqual({ ...createPatient, @@ -55,8 +53,8 @@ describe('[patient] Update Patient Service', () => { expect(findPatient?.paymentMethod).toBe(newPatientInfos.paymentMethod); expect(findPatient?.paymentMethod).not.toBe(fakePatient.paymentMethod); - expect(findPatient?.phone).not.toBe(fakePatient.phone); - expect(findPatient?.phone).toBe(newPatientInfos.phone); + expect(findPatient?.telephone).not.toBe(fakePatient.telephone); + expect(findPatient?.telephone).toBe(newPatientInfos.telephone); }); it('should throw conflict exception if patient do not exist', async () => { @@ -67,7 +65,7 @@ describe('[patient] Update Patient Service', () => { }; await expect(service.execute(newPatientInfos)).rejects.toThrow( - new ConflictException(PATIENT_ERROR_MESSAGES['PATIENT_NOT_FOUND']) + new ConflictException(PATIENT_ERROR_MESSAGES['PATIENT_NOT_FOUND']), ); }); }); diff --git a/libs/core-rest-api/core/tsconfig.lib.json b/libs/core-rest-api/core/tsconfig.lib.json index d88fd089..17587d64 100644 --- a/libs/core-rest-api/core/tsconfig.lib.json +++ b/libs/core-rest-api/core/tsconfig.lib.json @@ -10,6 +10,9 @@ "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true }, - "include": ["src/**/*.ts", "../adapters/src/controllers/api/shared/utils/e2e-tests-initial-setup.ts"], + "include": [ + "src/**/*.ts", + "../adapters/src/controllers/api/shared/utils/e2e-tests-initial-setup.ts" + ], "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"] } diff --git a/package.json b/package.json index 4c3a1b06..b6007ca9 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "conventional-graduate": "lerna version --yes --conventional-graduate --conventional-commits --changelog-preset ./changelog-preset.config.js", "conventional-graduate:no-push": "lerna version --yes --conventional-graduate --conventional-commits --changelog-preset ./changelog-preset.config.js --no-push", "test-scripts": "************************ TESTS SCRIPTS ********************", - "test:unit": "nx run-many --target=test --all=true", - "test:e2e": "nx run-many --target=e2e --all=true --parallel=3", + "test:unit": "nx run-many --target=test --all=true --verbose=true", + "test:e2e": "nx run-many --target=e2e --all=true --parallel=3 --verbose=true", "test:adapters:e2e": "vitest run --config ./libs/core-rest-api/adapters/vitest.config.e2e.ts", "prisma-scripts": "********************** PRISMA SCRIPTS ********************", "prisma:core:schema:validate": "prisma validate --schema=./libs/core-rest-api/adapters/src/database/infra/prisma/postgresql.schema.prisma", diff --git a/tsconfig.base.json b/tsconfig.base.json index 4be574a0..ae86395a 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -18,9 +18,9 @@ "esModuleInterop": true, "paths": { "@clinicControl/core-rest-api/adapters/src/*": [ - "libs/core-rest-api/adapters/src/*" + "./libs/core-rest-api/adapters/src/*" ], - "@clinicControl/core-rest-api/core/src/*": ["libs/core-rest-api/core/src/*"], + "@clinicControl/core-rest-api/core/src/*": ["./libs/core-rest-api/core/src/*"], "@clinicControl/root/*": ["./*"] } },