-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
86 additions
and
26 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
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
27 changes: 27 additions & 0 deletions
27
server/src/presentation/controllers/appointment/AppointmentControllers.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,27 @@ | ||
import { NextFunction, Response } from "express"; | ||
import { CustomRequest, StatusCode } from "../../../types"; | ||
import AppointmentUseCase from "../../../use_case/appointment/AppointmentUseCase"; | ||
import AppointmentValidator from "../../validators/AppointmentValidator"; | ||
|
||
export default class AppointmentController { | ||
constructor( | ||
private appointmentUseCase: AppointmentUseCase, | ||
private appointmentValidator: AppointmentValidator | ||
) { } | ||
|
||
async create(req: CustomRequest, res: Response, next: NextFunction) { | ||
try { | ||
const { error } = this.appointmentValidator.validate(req.body.appointment); | ||
if (error) { | ||
return res.status(StatusCode.BadRequest).json({ message: error.details[0].message }); | ||
} | ||
const { appointment } = req.body; | ||
const patientId = req.patient?.id; | ||
await this.appointmentUseCase.create(appointment, patientId!); | ||
res.status(StatusCode.Success).json({ message: "Appointment created successfully" }); | ||
} catch (error) { | ||
next(error); | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
server/src/presentation/routers/appointment/AppointmentRoutes.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,26 @@ | ||
import express from 'express' | ||
import AppointmentRepository from '../../../infrastructure/repositories/AppointmentRepository'; | ||
import SlotRepository from '../../../infrastructure/repositories/SlotRepository'; | ||
import AppointmentUseCase from '../../../use_case/appointment/AppointmentUseCase'; | ||
import AppointmentController from '../../controllers/appointment/AppointmentControllers'; | ||
import AppointmentValidator from '../../validators/AppointmentValidator'; | ||
import PatientAuthMiddleware from '../../middlewares/PatientAuthMiddleware'; | ||
import JWTService from '../../../infrastructure/services/JWTService'; | ||
|
||
const router = express.Router(); | ||
|
||
|
||
const appointmentRepository = new AppointmentRepository(); | ||
const slotRepository = new SlotRepository(); | ||
const tokenService = new JWTService() | ||
|
||
const appointmentUseCase = new AppointmentUseCase(appointmentRepository, slotRepository); | ||
|
||
const appointmentValidator = new AppointmentValidator() | ||
const appointmentController = new AppointmentController(appointmentUseCase, appointmentValidator); | ||
|
||
const authorizePatient = new PatientAuthMiddleware(tokenService); | ||
|
||
router.post('/', authorizePatient.exec.bind(authorizePatient), appointmentController.create.bind(appointmentController)); | ||
|
||
export default router; |
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
22 changes: 22 additions & 0 deletions
22
server/src/presentation/validators/AppointmentValidator.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,22 @@ | ||
import Joi from "joi"; | ||
import IAppointment, { AppointmentType } from "../../domain/entities/IAppointment"; | ||
|
||
export default class AppointmentValidator { | ||
private schema: Joi.ObjectSchema; | ||
|
||
constructor() { | ||
this.schema = Joi.object({ | ||
doctorId: Joi.string().required(), | ||
patientId: Joi.string().required(), | ||
slotId: Joi.string().required(), | ||
appointmentType: Joi.string().valid(...Object.values(AppointmentType)).required(), | ||
appointmentDate: Joi.string().isoDate().required(), | ||
reason: Joi.string().optional(), | ||
notes: Joi.string().optional(), | ||
}); | ||
} | ||
|
||
validate(appointment: IAppointment) { | ||
return this.schema.validate(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
7c6fd89
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
avm-care – ./
avm-care-sinans-projects-8d312afe.vercel.app
avm-care-git-main-sinans-projects-8d312afe.vercel.app
avm-care.vercel.app