-
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 pull request #23 from SkinSightYnov/dev
Dev
- Loading branch information
Showing
16 changed files
with
345 additions
and
8 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
prisma/migrations/20240222105619_update_firstname_lastname/migration.sql
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,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; |
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
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); | ||
} | ||
} |
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,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 {} |
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,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) { | ||
return `This action updates a #${id} appointment`; | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} appointment`; | ||
} | ||
} |
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 @@ | ||
export class CreateAppointmentDto {} |
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,4 @@ | ||
import { PartialType } from '@nestjs/swagger'; | ||
import { CreateAppointmentDto } from './create-appointment.dto'; | ||
|
||
export class UpdateAppointmentDto extends PartialType(CreateAppointmentDto) {} |
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,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; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class CreatePatientDto {} |
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,4 @@ | ||
import { PartialType } from '@nestjs/swagger'; | ||
import { CreatePatientDto } from './create-patient.dto'; | ||
|
||
export class UpdatePatientDto extends PartialType(CreatePatientDto) {} |
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,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[]; | ||
} |
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,82 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Param, | ||
UseGuards, | ||
Req, | ||
HttpException, | ||
Post, | ||
} 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); | ||
// } | ||
} |
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,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 {} |
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,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) { | ||
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) { | ||
return `This action updates a #${id} patient`; | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} patient`; | ||
} | ||
} |
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