Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ItaloRAmaral/cliniccontrol into 120…
Browse files Browse the repository at this point in the history
…-criacao-de-endpoint-de-criacao-de-consultas
  • Loading branch information
luanavfg committed Feb 5, 2024
2 parents 1f1ab00 + 5fcb812 commit 299afed
Show file tree
Hide file tree
Showing 24 changed files with 1,820 additions and 1,366 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.7.0-beta.1](https://github.com/ItaloRAmaral/cliniccontrol/compare/[email protected]@1.7.0-beta.1) (2024-02-04)

### Features

- add mapper for registry ([e0d1247](https://github.com/ItaloRAmaral/cliniccontrol/commit/e0d1247dae8996baefaeb5fc0cbb6146b3916885))
- **CC-118:** add controllers and service in api module ([452c503](https://github.com/ItaloRAmaral/cliniccontrol/commit/452c503e0f063855dc707c7d29d866eb2ecd438f))
- **CC-118:** add dto to appointment registry ([44dcdee](https://github.com/ItaloRAmaral/cliniccontrol/commit/44dcdeee5ff32e50e2eddec02b134f6cc4d4b000))
- **CC-118:** add methods in prisma registry repository ([b944e02](https://github.com/ItaloRAmaral/cliniccontrol/commit/b944e0229ac910ea7be8e4f26628c18640eb66fd))
- **CC-118:** add registry fake client ([1615baa](https://github.com/ItaloRAmaral/cliniccontrol/commit/1615baa02af1250c893fdc76a6d2f53c55db75d7))
- **CC-118:** add registry mapper ([3f69213](https://github.com/ItaloRAmaral/cliniccontrol/commit/3f69213347e77136a95477a2e80ea300ba266ff3))
- **CC-118:** add repository in repositories module ([8142178](https://github.com/ItaloRAmaral/cliniccontrol/commit/8142178c2331615f0caf54677431ba32bc5c34e1))
- **CC-118:** add test e2e to appointment registry ([f4a4d78](https://github.com/ItaloRAmaral/cliniccontrol/commit/f4a4d78886a762bbd6f2033d0b495a4c8fdbec05))
- **CC-118:** create controller to appointment registry ([f11b910](https://github.com/ItaloRAmaral/cliniccontrol/commit/f11b9105394f6e202ac5c7ad631e882b9e311f8a))
- **CC-118:** create fake client to registry ([a547515](https://github.com/ItaloRAmaral/cliniccontrol/commit/a547515207a3dfad0968eefb21b581f56b9c3d14))
- **CC-118:** create service to appointment registry ([0b39908](https://github.com/ItaloRAmaral/cliniccontrol/commit/0b399083a9bf7478fa8f8f64961749d098092720))
- create PostgresqlPrismaOrmRegistryRepository ([cdbc7de](https://github.com/ItaloRAmaral/cliniccontrol/commit/cdbc7de00a77efe081c2d3b9082ad8a3fce481cf))

## [1.7.0-beta.0](https://github.com/ItaloRAmaral/cliniccontrol/compare/[email protected]@1.7.0-beta.0) (2024-01-12)

### Features
Expand Down
17 changes: 17 additions & 0 deletions apps/core-rest-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.4.0-beta.1](https://github.com/ItaloRAmaral/cliniccontrol/compare/@cliniccontrol/[email protected]...@cliniccontrol/[email protected]) (2024-02-04)

### Features

- add mapper for registry ([e0d1247](https://github.com/ItaloRAmaral/cliniccontrol/commit/e0d1247dae8996baefaeb5fc0cbb6146b3916885))
- **CC-118:** add controllers and service in api module ([452c503](https://github.com/ItaloRAmaral/cliniccontrol/commit/452c503e0f063855dc707c7d29d866eb2ecd438f))
- **CC-118:** add dto to appointment registry ([44dcdee](https://github.com/ItaloRAmaral/cliniccontrol/commit/44dcdeee5ff32e50e2eddec02b134f6cc4d4b000))
- **CC-118:** add methods in prisma registry repository ([b944e02](https://github.com/ItaloRAmaral/cliniccontrol/commit/b944e0229ac910ea7be8e4f26628c18640eb66fd))
- **CC-118:** add registry fake client ([1615baa](https://github.com/ItaloRAmaral/cliniccontrol/commit/1615baa02af1250c893fdc76a6d2f53c55db75d7))
- **CC-118:** add registry mapper ([3f69213](https://github.com/ItaloRAmaral/cliniccontrol/commit/3f69213347e77136a95477a2e80ea300ba266ff3))
- **CC-118:** add repository in repositories module ([8142178](https://github.com/ItaloRAmaral/cliniccontrol/commit/8142178c2331615f0caf54677431ba32bc5c34e1))
- **CC-118:** add test e2e to appointment registry ([f4a4d78](https://github.com/ItaloRAmaral/cliniccontrol/commit/f4a4d78886a762bbd6f2033d0b495a4c8fdbec05))
- **CC-118:** create controller to appointment registry ([f11b910](https://github.com/ItaloRAmaral/cliniccontrol/commit/f11b9105394f6e202ac5c7ad631e882b9e311f8a))
- **CC-118:** create fake client to registry ([a547515](https://github.com/ItaloRAmaral/cliniccontrol/commit/a547515207a3dfad0968eefb21b581f56b9c3d14))
- **CC-118:** create service to appointment registry ([0b39908](https://github.com/ItaloRAmaral/cliniccontrol/commit/0b399083a9bf7478fa8f8f64961749d098092720))
- create PostgresqlPrismaOrmRegistryRepository ([cdbc7de](https://github.com/ItaloRAmaral/cliniccontrol/commit/cdbc7de00a77efe081c2d3b9082ad8a3fce481cf))

## [1.4.0-beta.0](https://github.com/ItaloRAmaral/cliniccontrol/compare/@cliniccontrol/[email protected]...@cliniccontrol/[email protected]) (2024-01-12)

### Features
Expand Down
25 changes: 25 additions & 0 deletions apps/core-rest-api/http/appointment-registry.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@authToken = {{$dotenv AUTH_TOKEN}}
@apiKey = {{$dotenv API_KEY}}

### Create New Appointment Registry

# @name create_patient_appointment_registry
POST http://localhost:3333/core/appointment-registry/create HTTP/1.1
Content-Type: application/json
Authorization: Bearer {{authToken}}

{
"registry": {
"observations": "well"
},
"psychologistId": "{{$dotenv PSYCHOLOGIST_ID}}",
"patientId": "{{$dotenv PATIENT_ID}}"
}

### Update Registry

# @name update_patient_appointment_registry
PATCH http://localhost:3333/core/appointment-registry/update HTTP/1.1

Content-Type: application/json
Authorization: Bearer {{authToken}}
2 changes: 1 addition & 1 deletion apps/core-rest-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cliniccontrol/core-rest-api",
"version": "1.4.0-beta.0",
"version": "1.4.0-beta.1",
"license": "MIT",
"authors": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { NestjsCreateAppointmentService } from './use-cases/appointment/create-a
import { NestjsCreateClinicService } from './use-cases/clinic/create-clinic/nestjs-create-clinic.service';
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 { CreatePatientAppointmentRegistryController } from './use-cases/patient-appointment-registry/create-patient-appointment-registry/create-patient-appointment-registry.controller';
import { NestjsCreatePatientAppointmentRegistryService } from './use-cases/patient-appointment-registry/create-patient-appointment-registry/nestjs-create-patient-appointment-registry.service';
import { NestjsCreatePatientService } from './use-cases/patient/create-patient/nestjs-create-patient.service';
import { NestjsDeletePatientService } from './use-cases/patient/delete-patient/nestjs-delete-patient.service';
import { NestjsAuthenticatePsychologistService } from './use-cases/psychologist/authenticate-psychologist/nestjs-authenticate-psychologist.service';
Expand Down Expand Up @@ -53,6 +55,7 @@ import { NestjsUpdatePsychologistService } from './use-cases/psychologist/update
DeleteClinicController,
CreatePatientController,
DeletePatientController,
CreatePatientAppointmentRegistryController,
CreateAppointmentController
],
providers: [
Expand All @@ -67,6 +70,7 @@ import { NestjsUpdatePsychologistService } from './use-cases/psychologist/update
NestjsDeleteClinicService,
NestjsCreatePatientService,
NestjsDeletePatientService,
NestjsCreatePatientAppointmentRegistryService,
NestjsCreateAppointmentService
],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Body, Controller, Post } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { CreatePatientAppointmentRegistryDto } from '../../../../../../core/domains/patient-appointment-registry/use-cases/create-appointment-registry/create-appointment-registry-dto';
import { GlobalAppHttpException } from '../../../../../../shared/errors/globalAppHttpException';
import { CreatePatientAppointmentRegistryOutputDto } from './dto';
import { NestjsCreatePatientAppointmentRegistryService } from './nestjs-create-patient-appointment-registry.service';

@ApiTags('Create Patient Appointment Registry')
@Controller({
path: 'appointment-registry',
})
export class CreatePatientAppointmentRegistryController {
constructor(
private createPatientAppointmentRegistryService: NestjsCreatePatientAppointmentRegistryService,
) {}

@Post('create')
async execute(
@Body() createPatientAppointmentRegistryDto: CreatePatientAppointmentRegistryDto,
): Promise<CreatePatientAppointmentRegistryOutputDto> {
try {
await this.createPatientAppointmentRegistryService.execute(
createPatientAppointmentRegistryDto,
);

return { message: 'Appointment registry created successfully' };
} catch (error: unknown) {
throw new GlobalAppHttpException(error);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import request from 'supertest';

import { INestApplication } from '@nestjs/common';

import { setupE2ETest } from '../../../../../../../../tests/utils/e2e-tests-initial-setup';
import { Registry } from '../../../../../../core/domains/patient-appointment-registry/entities/registry/dto';
import { CreatePatientAppointmentRegistryDto } from '../../../../../../core/domains/patient-appointment-registry/use-cases/create-appointment-registry/create-appointment-registry-dto';
import { PatientEntity } from '../../../../../../core/domains/patient/entities/patient/entity';
import { PsychologistEntity } from '../../../../../../core/domains/psychologist/entities/psychologist/entity';

describe('[E2E] - Create Appointment Registry', () => {
let app: INestApplication;

let access_token: string;

let patient: PatientEntity;
let psychologist: PsychologistEntity;
let registry: Registry;

beforeAll(async () => {
const setup = await setupE2ETest();

app = setup.app;

access_token = setup.access_token;

patient = setup.patient;
psychologist = setup.psychologist;

registry = {
observations: 'Patient is doing well',
};
});

it('[POST] - Should successfully create a new registry', async () => {
const appointmentRegistry: CreatePatientAppointmentRegistryDto = {
patientId: patient.id,
psychologistId: psychologist.id,
registry,
};

const createdPatientAppointmentRegistry = await request(app.getHttpServer())
.post('/appointment-registry/create')
.set('Authorization', `Bearer ${access_token}`)
.send(appointmentRegistry);

expect(createdPatientAppointmentRegistry.statusCode).toBe(201);
expect(createdPatientAppointmentRegistry.body.message).toBe(
'Appointment registry created successfully',
);
});

it('[POST] - Should return an error when trying to create a registry with an invalid patient id', async () => {
const appointmentRegistry: CreatePatientAppointmentRegistryDto = {
patientId: 'invalid_patient_id',
psychologistId: psychologist.id,
registry,
};

const createdPatientAppointmentRegistry = await request(app.getHttpServer())
.post('/appointment-registry/create')
.set('Authorization', `Bearer ${access_token}`)
.send(appointmentRegistry);

expect(createdPatientAppointmentRegistry.statusCode).toBe(409);
expect(createdPatientAppointmentRegistry.body.message).toBe('patient not found');
});

it('[POST] - Should return an error when trying to create a registry with an invalid psychologist id', async () => {
const appointmentRegistry: CreatePatientAppointmentRegistryDto = {
patientId: patient.id,
psychologistId: 'invalid_psychologist_id',
registry,
};

const createdPatientAppointmentRegistry = await request(app.getHttpServer())
.post('/appointment-registry/create')
.set('Authorization', `Bearer ${access_token}`)
.send(appointmentRegistry);

expect(createdPatientAppointmentRegistry.statusCode).toBe(409);
expect(createdPatientAppointmentRegistry.body.message).toBe('psychologist not found');
});

it('[POST] - Should return an error when trying to create a registry without token', async () => {
const appointmentRegistry: CreatePatientAppointmentRegistryDto = {
patientId: patient.id,
psychologistId: psychologist.id,
registry,
};

const createdPatientAppointmentRegistry = await request(app.getHttpServer())
.post('/appointment-registry/create')
.send(appointmentRegistry);

expect(createdPatientAppointmentRegistry.statusCode).toBe(401);
expect(createdPatientAppointmentRegistry.body.message).toBe('Invalid JWT token');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IsString } from "class-validator";

export class CreatePatientAppointmentRegistryOutputDto {
@IsString()
message!: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Injectable } from '@nestjs/common';
import { PatientAppointmentRegistryDatabaseRepository } from '../../../../../../core/domains/patient-appointment-registry/repositories/database-repository';
import { CreatePatientAppointmentRegistryService } from '../../../../../../core/domains/patient-appointment-registry/use-cases/create-appointment-registry/create-appointment-registry.service';
import { PatientDatabaseRepository } from '../../../../../../core/domains/patient/repositories/database-repository';
import { PsychologistDatabaseRepository } from '../../../../../../core/domains/psychologist/repositories/database-repository';

@Injectable()
export class NestjsCreatePatientAppointmentRegistryService extends CreatePatientAppointmentRegistryService {
constructor(
psychologistDatabaseRepository: PsychologistDatabaseRepository,
patientDatabaseRepository: PatientDatabaseRepository,
patientAppointmentRegistryDatabaseRepository: PatientAppointmentRegistryDatabaseRepository,
)
{
super(
psychologistDatabaseRepository,
patientDatabaseRepository,
patientAppointmentRegistryDatabaseRepository
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Warnings:
- You are about to drop the `patient_appointments_registry` table. If the table is not empty, all the data it contains will be lost.
*/
-- 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";

-- DropTable
DROP TABLE "patient_appointments_registry";

-- CreateTable
CREATE TABLE "patient_appointment_registry" (
"id" TEXT NOT NULL,
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"registry" JSON NOT NULL,
"patient_id" TEXT NOT NULL,
"psychologist_id" TEXT NOT NULL,

CONSTRAINT "patient_appointment_registry_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "patient_appointment_registry" ADD CONSTRAINT "patient_appointment_registry_patient_id_fkey" FOREIGN KEY ("patient_id") REFERENCES "patient"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "patient_appointment_registry" ADD CONSTRAINT "patient_appointment_registry_psychologist_id_fkey" FOREIGN KEY ("psychologist_id") REFERENCES "psychologist"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ enum PaymentMethod {
}

model Psychologist {
id String @id @default(uuid())
name String
email String @unique
password String
role Role @default(PSYCHOLOGIST)
price Int? @default(0)
plan Plan @default(BASIC)
totalYearEarnings Int? @default(0) @map("total_year_earnings")
totalMonthEarnings Int? @default(0) @map("total_month_earnings")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamptz(6)
clinic Clinic[]
patient Patient[]
appointment Appointment[]
patientAppointmentsRegistry PatientAppointmentsRegistry[]
id String @id @default(uuid())
name String
email String @unique
password String
role Role @default(PSYCHOLOGIST)
price Int? @default(0)
plan Plan @default(BASIC)
totalYearEarnings Int? @default(0) @map("total_year_earnings")
totalMonthEarnings Int? @default(0) @map("total_month_earnings")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamptz(6)
clinic Clinic[]
patient Patient[]
appointment Appointment[]
patientAppointmentRegistry PatientAppointmentRegistry[]
@@map("psychologist")
}
Expand All @@ -69,16 +69,16 @@ model Clinic {
}

model Patient {
id String @id @default(uuid())
name String
email String @unique
cpf String @unique
telephone String
paymentMethod PaymentMethod @default(HEALTH_INSURANCE) @map("payment_method")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamptz(6)
appointment Appointment[]
patientAppointmentsRegistry PatientAppointmentsRegistry[]
id String @id @default(uuid())
name String
email String @unique
cpf String @unique
telephone String
paymentMethod PaymentMethod @default(HEALTH_INSURANCE) @map("payment_method")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamptz(6)
appointment Appointment[]
patientAppointmentRegistry PatientAppointmentRegistry[]
psychologistId String @map("psychologist_id")
psychologist Psychologist @relation(fields: [psychologistId], references: [id], onDelete: Cascade)
Expand Down Expand Up @@ -113,7 +113,7 @@ model Appointment {
@@map("appointment")
}

model PatientAppointmentsRegistry {
model PatientAppointmentRegistry {
id String @id @default(uuid())
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamptz(6)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
Expand All @@ -124,5 +124,5 @@ model PatientAppointmentsRegistry {
psychologistId String @map("psychologist_id")
psychologist Psychologist @relation(fields: [psychologistId], references: [id], onDelete: Cascade)
@@map("patient_appointments_registry")
@@map("patient_appointment_registry")
}
Loading

0 comments on commit 299afed

Please sign in to comment.