Skip to content

Commit

Permalink
Merge pull request #23 from SkinSightYnov/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
R-o-h-t authored Feb 22, 2024
2 parents bbd8905 + 829102d commit f02151a
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:
- Added the required column `firstName` to the `User` table without a default value. This is not possible if the table is not empty.
- Added the required column `lastName` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "User" ADD COLUMN "firstName" TEXT NOT NULL,
ADD COLUMN "lastName" TEXT NOT NULL;
4 changes: 4 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { PrismaModule } from './prisma/prisma.module';
import { ConsultationsModule } from './consultations/consultations.module';
import { MedecinsModule } from './medecins/medecins.module';
import { DermatologuesModule } from './dermatologues/dermatologues.module';
import { AppointmentsModule } from './appointments/appointments.module';
import { PatientsModule } from './patients/patients.module';

@Module({
imports: [
Expand All @@ -27,6 +29,8 @@ import { DermatologuesModule } from './dermatologues/dermatologues.module';
ConsultationsModule,
MedecinsModule,
DermatologuesModule,
AppointmentsModule,
PatientsModule,
],
controllers: [AppController],
providers: [
Expand Down
45 changes: 45 additions & 0 deletions src/appointments/appointments.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
} from '@nestjs/common';
import { AppointmentsService } from './appointments.service';
import { CreateAppointmentDto } from './dto/create-appointment.dto';
import { UpdateAppointmentDto } from './dto/update-appointment.dto';

@Controller('appointments')
export class AppointmentsController {
constructor(private readonly appointmentsService: AppointmentsService) {}

@Post()
create(@Body() createAppointmentDto: CreateAppointmentDto) {
return this.appointmentsService.create(createAppointmentDto);
}

@Get()
findAll() {
return this.appointmentsService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.appointmentsService.findOne(+id);
}

@Patch(':id')
update(
@Param('id') id: string,
@Body() updateAppointmentDto: UpdateAppointmentDto,
) {
return this.appointmentsService.update(+id, updateAppointmentDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.appointmentsService.remove(+id);
}
}
12 changes: 12 additions & 0 deletions src/appointments/appointments.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { AppointmentsService } from './appointments.service';
import { AppointmentsController } from './appointments.controller';
import { PrismaModule } from 'src/prisma/prisma.module';

@Module({
imports: [PrismaModule],
controllers: [AppointmentsController],
providers: [AppointmentsService],
exports: [AppointmentsService],
})
export class AppointmentsModule {}
50 changes: 50 additions & 0 deletions src/appointments/appointments.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Injectable } from '@nestjs/common';
import { CreateAppointmentDto } from './dto/create-appointment.dto';
import { UpdateAppointmentDto } from './dto/update-appointment.dto';
import { PrismaService } from 'src/prisma/prisma.service';
import { Appointment } from '@prisma/client';

@Injectable()
export class AppointmentsService {
constructor(private readonly prismaService: PrismaService) {}

create(createAppointmentDto: CreateAppointmentDto) {
this.prismaService.appointment.create({
data: createAppointmentDto as Appointment,
});
}

findByPatientId(patientId: string) {
return this.prismaService.appointment.findMany({
where: {
idPatient: patientId,
},
});
}

findByDermatologueId(dermatologueId: string) {
return this.prismaService.appointment.findMany({
where: {
idDermatologue: dermatologueId,
},
});
}

// updateStatus(appointmentId: string, status: App) {

findAll() {
return this.prismaService.appointment.findMany();
}

findOne(id: number) {
return `This action returns a #${id} appointment`;
}

update(id: number, updateAppointmentDto: UpdateAppointmentDto) {

Check failure on line 43 in src/appointments/appointments.service.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

'updateAppointmentDto' is defined but never used
return `This action updates a #${id} appointment`;
}

remove(id: number) {
return `This action removes a #${id} appointment`;
}
}
1 change: 1 addition & 0 deletions src/appointments/dto/create-appointment.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CreateAppointmentDto {}
4 changes: 4 additions & 0 deletions src/appointments/dto/update-appointment.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/swagger';
import { CreateAppointmentDto } from './create-appointment.dto';

export class UpdateAppointmentDto extends PartialType(CreateAppointmentDto) {}
28 changes: 28 additions & 0 deletions src/appointments/entities/appointment.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ApiProperty } from '@nestjs/swagger';
import { Appointment, statusAppointment } from '@prisma/client';

export class AppointmentEntity implements Appointment {
@ApiProperty()
id: string;

@ApiProperty()
updatedAt: Date;

@ApiProperty()
createdAt: Date;

@ApiProperty()
idDermatologue: string;

@ApiProperty()
idPatient: string;

@ApiProperty()
date: Date;

@ApiProperty()
status: statusAppointment;

@ApiProperty()
idConsultation: string;
}
7 changes: 5 additions & 2 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ export class AuthService {
};
}

async createAccessToken(userId: string) {
return this.jwtService.sign({ userId: userId }, { expiresIn: '15m' });
async createAccessToken(userId: string, role: Role) {
return this.jwtService.sign(
{ userId: userId, role: role },
{ expiresIn: '15m' },
);
}

async createRefreshToken(userId: string, role: Role) {
Expand Down
1 change: 1 addition & 0 deletions src/patients/dto/create-patient.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CreatePatientDto {}
4 changes: 4 additions & 0 deletions src/patients/dto/update-patient.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/swagger';
import { CreatePatientDto } from './create-patient.dto';

export class UpdatePatientDto extends PartialType(CreatePatientDto) {}
54 changes: 54 additions & 0 deletions src/patients/entities/patient.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { ApiProperty } from '@nestjs/swagger';
import { Prisma, User } from '@prisma/client';
import { Exclude } from 'class-transformer';

export class PatientEntity implements User {
constructor(partial: Partial<PatientEntity>) {
Object.assign(this, partial);
}

@ApiProperty()
id: string;

@ApiProperty()
updatedAt: Date;

@ApiProperty()
createdAt: Date;

@ApiProperty()
firstName: string;

@ApiProperty()
lastName: string;

@ApiProperty()
role: 'PATIENT';

@ApiProperty()
email: string;

@ApiProperty()
sexe: string;

@Exclude()
password: string;

@ApiProperty()
rppsNumber: string;

@ApiProperty()
address: string;

@ApiProperty()
city: string;

@ApiProperty()
zipCode: string;

@ApiProperty()
secuNumber: string;

@ApiProperty()
consultationPatient: Prisma.ConsultationCreateInput[];
}
82 changes: 82 additions & 0 deletions src/patients/patients.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
Controller,
Get,
Param,
UseGuards,
Req,
HttpException,
Post,

Check failure on line 8 in src/patients/patients.controller.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

'Post' is defined but never used
} from '@nestjs/common';
import { PatientsService } from './patients.service';
import { ConsultationsService } from 'src/consultations/consultations.service';
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
import { ApiBearerAuth, ApiOkResponse } from '@nestjs/swagger';
import { Request } from 'express';
import { User } from '@prisma/client';
import { RolesGuard } from 'src/auth/roles.guard';
import { HasRole } from 'src/auth/has-role.decorator';
import { ConsultationEntity } from 'src/consultations/entities/consultation.entity';

@Controller('patients')
export class PatientsController {
constructor(
private readonly patientsService: PatientsService,
private readonly consultationService: ConsultationsService,
) {}

@Get()
findAll() {
return this.patientsService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.patientsService.findOne(+id);
}

@ApiBearerAuth()
@HasRole('PATIENT', 'ADMIN')
@UseGuards(JwtAuthGuard, RolesGuard)
@Get(':id/consultations')
getConsultationsByPatientId(@Param('id') id: string) {
return this.consultationService.getConsultationsByPatientId(id);
}

@ApiBearerAuth()
@HasRole('PATIENT', 'ADMIN')
@UseGuards(JwtAuthGuard, RolesGuard)
@Get(':id/consultations/:idConsultation')
@ApiOkResponse({ type: ConsultationEntity })
async getConsultationByPatientId(
@Param('id') id: string,
@Param('idConsultation') idConsultation: string,
@Req() req: Request,
) {
const userJwt = req.user as User;
if (userJwt.id !== id) {
throw new HttpException('Unauthorized', 401);
}

const consultation = await this.consultationService.findOne(idConsultation);
if (consultation.idPatient !== userJwt.id) {
throw new HttpException('Unauthorized', 401);
}

return consultation;
}

// @Get()
// findAll() {
// return this.patientsService.findAll();
// }

// @Patch(':id')
// update(@Param('id') id: string, @Body() updatePatientDto: UpdatePatientDto) {
// return this.patientsService.update(+id, updatePatientDto);
// }

// @Delete(':id')
// remove(@Param('id') id: string) {
// return this.patientsService.remove(+id);
// }
}
13 changes: 13 additions & 0 deletions src/patients/patients.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { PatientsService } from './patients.service';
import { PatientsController } from './patients.controller';
import { PrismaModule } from 'src/prisma/prisma.module';
import { ConsultationsService } from 'src/consultations/consultations.service';

@Module({
imports: [PrismaModule],
controllers: [PatientsController],
providers: [PatientsService, ConsultationsService],
exports: [PatientsService],
})
export class PatientsModule {}
26 changes: 26 additions & 0 deletions src/patients/patients.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreatePatientDto } from './dto/create-patient.dto';
import { UpdatePatientDto } from './dto/update-patient.dto';

@Injectable()
export class PatientsService {
create(createPatientDto: CreatePatientDto) {

Check failure on line 7 in src/patients/patients.service.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

'createPatientDto' is defined but never used
return 'This action adds a new patient';
}

findAll() {
return `This action returns all patients`;
}

findOne(id: number) {
return `This action returns a #${id} patient`;
}

update(id: number, updatePatientDto: UpdatePatientDto) {

Check failure on line 19 in src/patients/patients.service.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

'updatePatientDto' is defined but never used
return `This action updates a #${id} patient`;
}

remove(id: number) {
return `This action removes a #${id} patient`;
}
}
12 changes: 6 additions & 6 deletions src/users/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { Role } from '@prisma/client';
import {
IsEnum,
IsNotEmpty,
Expand All @@ -7,13 +8,12 @@ import {
MinLength,
} from 'class-validator';

export enum Role {
PATIENT = 'PATIENT',
MEDECIN = 'MEDECIN',
DERMATOLOGUE = 'DERMATOLOGUE',
}
// export enum Role {
// PATIENT = 'PATIENT',
// MEDECIN = 'MEDECIN',
// DERMATOLOGUE = 'DERMATOLOGUE',
// }
export class CreateUserDto {

@IsNotEmpty()
@IsString()
@ApiProperty()
Expand Down

0 comments on commit f02151a

Please sign in to comment.