-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:ItaloRAmaral/cliniccontrol into 113…
…-refatorar-aplicacao-para-concentrar-core-e-adapters-dentro-de-apps
- Loading branch information
Showing
40 changed files
with
379 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,12 @@ | |
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
## [1.6.0-beta.5](https://github.com/ItaloRAmaral/cliniccontrol/compare/[email protected]@1.6.0-beta.5) (2023-12-29) | ||
|
||
### Features | ||
|
||
- **CC-111:** delete patient endpoint ([d23b3d2](https://github.com/ItaloRAmaral/cliniccontrol/commit/d23b3d270d7068a8271e0140b3da29de371cc7e7)) | ||
|
||
## [1.6.0-beta.4](https://github.com/ItaloRAmaral/cliniccontrol/compare/[email protected]@1.6.0-beta.4) (2023-12-28) | ||
|
||
### Features | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
## [1.2.1-beta.2](https://github.com/ItaloRAmaral/cliniccontrol/compare/@cliniccontrol/[email protected]...@cliniccontrol/[email protected]) (2023-12-29) | ||
|
||
**Note:** Version bump only for package @cliniccontrol/core-rest-api | ||
|
||
## [1.2.1-beta.1](https://github.com/ItaloRAmaral/cliniccontrol/compare/@cliniccontrol/[email protected]...@cliniccontrol/[email protected]) (2023-12-21) | ||
|
||
**Note:** Version bump only for package @cliniccontrol/core-rest-api | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...pp/adapters/controllers/api/use-cases/patient/delete-patient/delete-patient.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Controller, Delete, Param } from '@nestjs/common'; | ||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger'; | ||
import { deleteMethodDocs } from './docs'; | ||
|
||
import { GlobalAppHttpException } from '../../../../../../shared/errors/globalAppHttpException'; | ||
|
||
import { TokenPayload } from '../../../../../auth/jwt.strategy'; | ||
import { CurrentUser } from '../../../decorators/current-user.decorator'; | ||
import { RouteParamsDto } from './dto'; | ||
import { NestjsDeletePatientService } from './nestjs-delete-patient.service'; | ||
|
||
@ApiTags('patient') | ||
@ApiBearerAuth() | ||
@Controller({ | ||
path: 'patient', | ||
}) | ||
export class DeletePatientController { | ||
constructor(private deletePatientService: NestjsDeletePatientService) {} | ||
|
||
@Delete(':patientId/delete') | ||
@ApiOperation(deleteMethodDocs) | ||
async execute( | ||
@Param() { patientId }: RouteParamsDto, | ||
@CurrentUser() currentUser: TokenPayload, | ||
) { | ||
try { | ||
const deletePatientDto = { | ||
patientId, | ||
psychologistId: currentUser.id, | ||
}; | ||
|
||
await this.deletePatientService.execute(deletePatientDto); | ||
|
||
return { | ||
message: 'Patient deleted successfully', | ||
}; | ||
} catch (error: unknown) { | ||
throw new GlobalAppHttpException(error); | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
.../app/adapters/controllers/api/use-cases/patient/delete-patient/delete-patient.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { fakerPT_BR as faker } from '@faker-js/faker'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import request from 'supertest'; | ||
|
||
import { setupE2ETest } from '../../../../../../../../tests/utils/e2e-tests-initial-setup'; | ||
import { PostgreSqlPrismaOrmService } from '../../../../../database/infra/prisma/prisma.service'; | ||
|
||
import { PatientFactory } from '../../../../../../../../tests/factories/make-patient'; | ||
import { PsychologistFactory } from '../../../../../../../../tests/factories/make-psychologist'; | ||
import { ClinicEntity } from '../../../../../../core/domains/clinic/entities/clinic/entity'; | ||
import { PatientEntity } from '../../../../../../core/domains/patient/entities/patient/entity'; | ||
|
||
describe('[E2E] - Delete Patient', async () => { | ||
let prisma: PostgreSqlPrismaOrmService; | ||
let app: INestApplication; | ||
|
||
let patientFactory: PatientFactory; | ||
let psychologistFactory: PsychologistFactory; | ||
|
||
let access_token: string; | ||
let invalid_access_token: string; | ||
|
||
let patient: PatientEntity; | ||
let clinic: ClinicEntity; | ||
|
||
beforeAll(async () => { | ||
const setup = await setupE2ETest(); | ||
|
||
prisma = setup.prisma; | ||
app = setup.app; | ||
|
||
patientFactory = setup.patientFactory; | ||
psychologistFactory = setup.psychologistFactory; | ||
|
||
access_token = setup.access_token; | ||
invalid_access_token = setup.invalid_access_token; | ||
|
||
clinic = setup.clinic; | ||
patient = setup.patient; | ||
}); | ||
|
||
it('[DELETE] - Should return an error when trying to delete a patient without access_token', async () => { | ||
const response = await request(app.getHttpServer()).delete( | ||
`/patient/${patient.id}/delete`, | ||
); | ||
|
||
expect(response.status).toBe(401); | ||
expect(response.body.message).toBe('Invalid JWT token'); | ||
}); | ||
|
||
it('[DELETE] - Should return an error when trying to delete a patient with invalid access_token', async () => { | ||
const response = await request(app.getHttpServer()) | ||
.delete(`/patient/${patient.id}/delete`) | ||
.set('Authorization', `Bearer ${invalid_access_token}`); | ||
|
||
expect(response.status).toBe(401); | ||
expect(response.body.message).toBe('Invalid JWT token'); | ||
}); | ||
|
||
it('[DELETE] - Should throw an error when trying to delete a patient which does not belong to the psychologist', async () => { | ||
const newPsychologist = await psychologistFactory.makePrismaPsychologist({ | ||
email: faker.internet.email(), | ||
}); | ||
|
||
const newPatient = await patientFactory.makePrismaPatient({ | ||
psychologistId: newPsychologist.id, | ||
clinicId: clinic.id, | ||
}); | ||
|
||
const response = await request(app.getHttpServer()) | ||
.delete(`/patient/${newPatient.id}/delete`) | ||
.set('Authorization', `Bearer ${access_token}`); | ||
|
||
expect(response.status).toBe(401); | ||
expect(response.body.message).toBe('this patient does not belong to you'); | ||
}); | ||
|
||
it('[DELETE] - Should throw an error when trying to delete a patient that does not exist', async () => { | ||
const fakePatientId = faker.string.uuid(); | ||
|
||
const response = await request(app.getHttpServer()) | ||
.delete(`/patient/${fakePatientId}/delete`) | ||
.set('Authorization', `Bearer ${access_token}`); | ||
|
||
expect(response.status).toBe(404); | ||
expect(response.body.message).toBe('patient not found'); | ||
}); | ||
|
||
it('[DELETE] - Should successfully delete a patient', async () => { | ||
const response = await request(app.getHttpServer()) | ||
.delete(`/patient/${patient.id}/delete`) | ||
.set('Authorization', `Bearer ${access_token}`); | ||
|
||
const isPatientExist = await prisma.patient.findUnique({ | ||
where: { | ||
id: patient.id, | ||
}, | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.message).toBe('Patient deleted successfully'); | ||
|
||
expect(isPatientExist).toBe(null); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
apps/core-rest-api/src/app/adapters/controllers/api/use-cases/patient/delete-patient/docs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { OperationObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface'; | ||
|
||
const description = ` | ||
--- | ||
\`Experimental\` | ||
--- | ||
### Delete a Patient in the system | ||
This endpoint help you to Delete a patient. | ||
You must at least provide one of the following body parameters | ||
`; | ||
|
||
export const deleteMethodDocs: Partial<OperationObject> = { | ||
summary: 'Delete a patient', | ||
description, | ||
}; |
6 changes: 6 additions & 0 deletions
6
apps/core-rest-api/src/app/adapters/controllers/api/use-cases/patient/delete-patient/dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IsString } from 'class-validator'; | ||
|
||
export class RouteParamsDto { | ||
@IsString() | ||
patientId!: string; | ||
} |
11 changes: 11 additions & 0 deletions
11
...dapters/controllers/api/use-cases/patient/delete-patient/nestjs-delete-patient.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { PatientDatabaseRepository } from '../../../../../../core/domains/patient/repositories/database-repository'; | ||
import { DeletePatientService } from '../../../../../../core/domains/patient/use-cases/delete-patient/delete-patient.service'; | ||
|
||
@Injectable() | ||
export class NestjsDeletePatientService extends DeletePatientService { | ||
constructor(patientDatabaseRepository: PatientDatabaseRepository) { | ||
super(patientDatabaseRepository); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.