Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | 7x 42x 42x 42x 7x 126x 7x 15x 15x 15x 30x 15x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x | import { checkPermission } from '@/middlewares/permission.middleware';
import { DoctorRepository } from '@/repositories/doctor.repo';
import { DoctorZODSchema } from '@/schemas/doctor/doctor.schema';
import { PermissionModel, PermissionVerb } from '@/services/permissions.service';
import { ENextFunction, Request, Response } from 'express';
import HttpStatusCode from '@/utils/HTTPStatusCodes';
import {
AuthGuard,
DeElete,
Get,
Middlewares,
Post,
Put,
RequestBody,
} from '@/decorators/router.decorator';
import { MainRouter } from '../router';
import { parseAPIVersion } from '@/config/app.config';
class DoctorsRouter extends MainRouter {
constructor(prefix: string) {
super(prefix, 'Doctors');
}
@AuthGuard()
@Middlewares([checkPermission(PermissionModel.DOCTOR, PermissionVerb.CREATE)])
@RequestBody(DoctorZODSchema.createDoctorSchema, 'createDoctorSchema')
@Post('/')
async createDoctor(req: Request, res: Response, next: NextFunction) {
try {
const body: TCreateDoctorSchema = req.body;
const resBody = await DoctorRepository.createDoctor(body);
res.status(resBody.error ? resBody.error.code : HttpStatusCode.OK).json(resBody);
next();
} catch (err) {
next(err);
}
}
@AuthGuard()
@Middlewares([checkPermission(PermissionModel.DOCTOR, PermissionVerb.READ)])
@RequestBody(DoctorZODSchema.searchDoctorSchema, 'searchDoctorSchema')
@Get('/')
async getDoctors(req: Request, res: Response, next: NextFunction) {
try {
const body: TSearchDoctorSchema = req.body;
const resBody = await DoctorRepository.getDoctors(body);
res.status(resBody.error ? resBody.error.code : HttpStatusCode.OK).json(resBody);
next();
} catch (err) {
next(err);
}
}
@AuthGuard()
@Middlewares([checkPermission(PermissionModel.DOCTOR, PermissionVerb.READ)])
@Get('/:docId')
async getDoctor(req: Request, res: Response, next: NextFunction) {
try {
const id = req.params.docId;
const resBody = await DoctorRepository.getDoctor(id);
res.status(resBody.error ? resBody.error.code : HttpStatusCode.OK).json(resBody);
next();
} catch (err) {
next(err);
}
}
@AuthGuard()
@Middlewares([checkPermission(PermissionModel.DOCTOR, PermissionVerb.UPDATE)])
@RequestBody(DoctorZODSchema.updateDoctorSchema, 'updateDoctorSchema')
@Put('/')
async updateDoctor(req: Request, res: Response, next: NextFunction) {
try {
const body: TUpdateDoctorSchema = req.body;
const resBody = await DoctorRepository.updateDoctor(body);
res.status(resBody.error ? resBody.error.code : HttpStatusCode.OK).json(resBody);
next();
} catch (err) {
next(err);
}
}
@AuthGuard()
@Middlewares([checkPermission(PermissionModel.DOCTOR, PermissionVerb.DELETE)])
@RequestBody(DoctorZODSchema.deleteDoctorSchema, 'deleteDoctorSchema')
@Delete('/')
async deleteDoctor(req: Request, res: Response, next: NextFunction) {
try {
const body: TDeleteDoctorSchema = req.body;
const resBody = await DoctorRepository.deleteDoctor(body);
res.status(resBody.error ? resBody.error.code : HttpStatusCode.OK).json(resBody);
next();
} catch (err) {
next(err);
}
}
@AuthGuard()
@Middlewares([checkPermission(PermissionModel.DOCTOR, PermissionVerb.DELETE)])
@RequestBody(DoctorZODSchema.validateDeleteSchema, 'validateDeleteSchema')
@Post('/confirm-delete')
async conformDeleteDoctor(req: Request, res: Response, next: NextFunction) {
try {
const body: TValidateDeleteSchema = req.body;
const resBody = await DoctorRepository.confirmDeleteDoctor(body);
res.status(resBody.error ? resBody.error.code : HttpStatusCode.OK).json(resBody);
next();
} catch (err) {
next(err);
}
}
}
const doctorsRoute = new DoctorsRouter(parseAPIVersion(1) + '/doctors');
export const doctorsRoutes = doctorsRoute.getRoute(doctorsRoute);
|