Skip to content

Commit

Permalink
server code updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Sep 27, 2024
1 parent f1605b5 commit 2306f1d
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 128 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "concurrently \"npm run dev --prefix client\" \"npm run dev --prefix server\"",
"format": "concurrently \"npm run format --prefix client\" \"npm run format --prefix server\"",
"dev": "concurrently \"npm run dev --prefix client\" \"npm run dev --prefix server\" \"stripe listen --forward-to localhost:8000/api/webhook\"",
"stripe":"stripe listen --forward-to localhost:8000/api/webhook"
"stripe": "stripe listen --forward-to localhost:8000/api/webhook"
},
"devDependencies": {
"concurrently": "^8.2.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import UnauthenticatedUseCases from "../../use_case/UnauthenticatedUseCases";
import { NextFunction, Request, Response } from "express";

export default class UnauthenticatedControllers {
constructor(private unauthenticatedUseCase: UnauthenticatedUseCases) {}
constructor(
private unauthenticatedUseCase: UnauthenticatedUseCases) {}

async getDoctors(req: Request, res: Response, next: NextFunction) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import AuthenticationUseCase from "../../../use_case/admin/AuthenticationUseCase
import { Cookie, StatusCode } from "../../../types";

export default class AuthenticationController {
constructor(private authUseCase: AuthenticationUseCase) {}
constructor(
private authUseCase: AuthenticationUseCase
) {
this.login = this.login.bind(this);
this.validateOtp = this.validateOtp.bind(this);
this.resendOtp = this.resendOtp.bind(this);
this.refreshAccessToken = this.refreshAccessToken.bind(this);
this.logout = this.logout.bind(this);
}

async login(req: Request, res: Response, next: NextFunction) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { DoctorsFilter, StatusCode } from "../../../types";
import IDoctor from "../../../domain/entities/IDoctor";

export default class AdminDoctorController {
constructor(private doctorUseCase: AdminDoctorUseCase) {}
constructor(
private doctorUseCase: AdminDoctorUseCase
) {
this.getDoctors = this.getDoctors.bind(this);
this.updateDoctor = this.updateDoctor.bind(this);
}

async getDoctors(req: Request, res: Response, next: NextFunction) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import AdminPatientUseCase from "../../../use_case/admin/PatientUseCase";
import { StatusCode } from "../../../types";

export default class AdminPatientController {
constructor(private adminPatientUseCase: AdminPatientUseCase) {}
constructor(
private adminPatientUseCase: AdminPatientUseCase
) {
this.getPatients = this.getPatients.bind(this);
this.updatePatient = this.updatePatient.bind(this);
}

async getPatients(req: Request, res: Response, next: NextFunction) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ export default class AppointmentController {
private createAppointmentUseCase: CreateAppointmentUseCase,
private getAppointmentUseCase: GetAppointmentUseCase,
private updateAppointmentUseCase: UpdateAppointmentUseCase
) {}
) {
this.create = this.create.bind(this);
this.handleStripeWebhook = this.handleStripeWebhook.bind(this);
this.getAppointmentsDoctor = this.getAppointmentsDoctor.bind(this);
this.getAppointmentDetails = this.getAppointmentDetails.bind(this);
this.getAppointmentSuccussDetails = this.getAppointmentSuccussDetails.bind(this);
this.getAppointmentsPatient = this.getAppointmentsPatient.bind(this);
this.updateAppointment = this.updateAppointment.bind(this);
this.updateStatusAndNotes = this.updateStatusAndNotes.bind(this);
}

async create(req: CustomRequest, res: Response, next: NextFunction) {
try {
Expand Down
12 changes: 11 additions & 1 deletion server/src/presentation/controllers/chat/ChatControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ export default class ChatController {
constructor(
private createChatUseCase: CreateChatUseCase,
private getChatUseCase: GetChatUseCase
) { }
) {
this.getChatsOfPatient = this.getChatsOfPatient.bind(this);
this.getChatsOfDoctor = this.getChatsOfDoctor.bind(this);
this.getPatientsDoctor = this.getPatientsDoctor.bind(this);
this.getMessagesOfChatPatient = this.getMessagesOfChatPatient.bind(this);
this.getMessagesOfChatDoctor = this.getMessagesOfChatDoctor.bind(this);
this.createChatPatient = this.createChatPatient.bind(this);
this.createChatDoctor = this.createChatDoctor.bind(this);
this.createMessageDoctor = this.createMessageDoctor.bind(this);
this.createMessagePatient = this.createMessagePatient.bind(this);
}
async getChatsOfPatient(req: CustomRequest, res: Response, next: NextFunction) {
try {
const patientId = req.patient?.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ import { Cookie, StatusCode } from "../../../types";
import IDoctor from "../../../domain/entities/IDoctor";

export default class AuthDoctorController {
constructor(private authDoctorUseCase: AuthenticationUseCase) {}

constructor(
private authDoctorUseCase: AuthenticationUseCase
) {
this.signin = this.signin.bind(this);
this.validateOtp = this.validateOtp.bind(this);
this.resendOtp = this.resendOtp.bind(this);
this.forgotPassword = this.forgotPassword.bind(this);
this.updatePassword = this.updatePassword.bind(this);
this.signup = this.signup.bind(this);
this.getUploadUrl = this.getUploadUrl.bind(this);
this.uploadProfileImage = this.uploadProfileImage.bind(this);
}
async signin(req: Request, res: Response, next: NextFunction) {
try {
const { email, password } = req.body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import NotificationUseCase from "../../../use_case/notification/NotificationUseC
export default class NotificationController {
constructor(
private notificationUseCase: NotificationUseCase
) {}
) {
this.getAllPatientNotifications = this.getAllPatientNotifications.bind(this);
this.getAllDoctorNotifications = this.getAllDoctorNotifications.bind(this);
this.clearMultipleNotifications = this.clearMultipleNotifications.bind(this);
this.clearSingleNotification = this.clearSingleNotification.bind(this);
}

async getAllPatientNotifications(req: CustomRequest, res: Response, next: NextFunction) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { NextFunction, Request, Response } from "express";
import { Cookie, StatusCode } from "../../../types";

export default class AuthPatientController {
constructor(private authUseCase: AuthenticationUseCase) {}
constructor(
private authUseCase: AuthenticationUseCase) {}

async register(req: Request, res: Response, next: NextFunction) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import PatientUseCase from "../../../use_case/patient/PatientUseCases";
import { CustomRequest, StatusCode } from "../../../types";

export default class PatientController {
constructor(private patientUseCase: PatientUseCase) {}
constructor(
private patientUseCase: PatientUseCase
) {}

async getProfile(req: CustomRequest, res: Response, next: NextFunction) {
try {
Expand Down
3 changes: 3 additions & 0 deletions server/src/presentation/middlewares/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import logger from "../../utils/logger";
import CustomError from "../../domain/entities/CustomError";

export default class ErrorHandler {
constructor() {
this.exec = this.exec.bind(this);
}
exec(error: any, req: Request, res: Response, next: NextFunction) {
const statusCode = error.statusCode || StatusCode.InternalServerError;
const message = error.message || "Internal Server Error";
Expand Down
12 changes: 6 additions & 6 deletions server/src/presentation/routers/admin/AdminRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express from "express";
import { Router } from "express";
import AdminPatientController from "../../controllers/admin/PatientController";
import AdminPatientUseCase from "../../../use_case/admin/PatientUseCase";
import PatientRepository from "../../../infrastructure/repositories/PatientRepository";
Expand All @@ -9,7 +9,7 @@ import DoctorRepository from "../../../infrastructure/repositories/DoctorReposit
import NodeMailerService from "../../../infrastructure/services/NodeMailerService";
import JoiService from "../../../infrastructure/services/JoiService";

const router = express.Router();
const router = Router();

const patientRepository = new PatientRepository();
const doctorRepository = new DoctorRepository();
Expand All @@ -23,11 +23,11 @@ const adminDoctorController = new AdminDoctorController(adminDoctorUseCase);

router
.route("/patient")
.get(adminPatientController.getPatients.bind(adminPatientController))
.put(adminPatientController.updatePatient.bind(adminPatientController));
.get(adminPatientController.getPatients)
.put(adminPatientController.updatePatient);
router
.route("/doctor")
.get(adminDoctorController.getDoctors.bind(adminDoctorController))
.put(adminDoctorController.updateDoctor.bind(adminDoctorController));
.get(adminDoctorController.getDoctors)
.put(adminDoctorController.updateDoctor);

export default router;
14 changes: 7 additions & 7 deletions server/src/presentation/routers/admin/AuthenticationRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express from "express";
import { Router } from "express";
import AuthenticationController from "../../controllers/admin/AuthenticationController";
import AuthenticationUseCase from "../../../use_case/admin/AuthenticationUseCase";
import DoctorRepository from "../../../infrastructure/repositories/DoctorRepository";
Expand All @@ -8,7 +8,7 @@ import NodeMailerService from "../../../infrastructure/services/NodeMailerServic
import OtpRepository from "../../../infrastructure/repositories/OtpRepository";
import JoiService from "../../../infrastructure/services/JoiService";

const router = express.Router();
const router = Router();

const adminRepository = new DoctorRepository();
const otpRepository = new OtpRepository();
Expand All @@ -27,10 +27,10 @@ const authUseCase = new AuthenticationUseCase(
);
const authController = new AuthenticationController(authUseCase);

router.post("/", authController.login.bind(authController));
router.post("/otp-verification", authController.validateOtp.bind(authController));
router.post("/resend-otp", authController.resendOtp.bind(authController));
router.get("/refresh", authController.refreshAccessToken.bind(authController));
router.post("/logout", authController.logout.bind(authController));
router.post("/", authController.login);
router.post("/otp-verification", authController.validateOtp);
router.post("/resend-otp", authController.resendOtp);
router.get("/refresh", authController.refreshAccessToken);
router.post("/logout", authController.logout);

export default router;
60 changes: 11 additions & 49 deletions server/src/presentation/routers/appointment/AppointmentRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express from "express";
import { Router } from "express";
import AppointmentRepository from "../../../infrastructure/repositories/AppointmentRepository";
import SlotRepository from "../../../infrastructure/repositories/SlotRepository";
import CreateAppointmentUseCase from "../../../use_case/appointment/CreateAppointmentUseCase";
Expand All @@ -16,7 +16,7 @@ import VideoSectionRepository from "../../../infrastructure/repositories/VideoSe
import PatientRepository from "../../../infrastructure/repositories/PatientRepository";
import DoctorRepository from "../../../infrastructure/repositories/DoctorRepository";

const router = express.Router();
const router = Router();

const appointmentRepository = new AppointmentRepository();
const slotRepository = new SlotRepository();
Expand Down Expand Up @@ -53,57 +53,19 @@ const authorizeDoctor = new DoctorAuthMiddleware(tokenService);

// ! Patient Routes

router.get(
"/patient/details/:appointmentId",
authorizePatient.exec,
appointmentController.getAppointmentDetails.bind(appointmentController)
);

router.get(
"/patient/succuss/:paymentId",
authorizePatient.exec,
appointmentController.getAppointmentSuccussDetails.bind(appointmentController)
);

router.post(
"/patient/",
authorizePatient.exec,
appointmentController.create.bind(appointmentController)
);

router.get(
"/patient/",
authorizePatient.exec,
appointmentController.getAppointmentsPatient.bind(appointmentController)
);

router.put(
"/patient/",
authorizePatient.exec,
appointmentController.updateStatusAndNotes.bind(appointmentController)
);
router.get("/patient/details/:appointmentId", authorizePatient.exec, appointmentController.getAppointmentDetails);
router.get("/patient/succuss/:paymentId", authorizePatient.exec, appointmentController.getAppointmentSuccussDetails);
router.post("/patient/", authorizePatient.exec, appointmentController.create);
router.get("/patient/", authorizePatient.exec, appointmentController.getAppointmentsPatient);
router.put("/patient/", authorizePatient.exec, appointmentController.updateStatusAndNotes);

// ! Doctor Routes

router.get(
"/doctor/details/:appointmentId",
authorizeDoctor.exec,
appointmentController.getAppointmentDetails.bind(appointmentController)
);

router.get(
"/doctor",
authorizeDoctor.exec,
appointmentController.getAppointmentsDoctor.bind(appointmentController)
);

router.put(
"/doctor/",
authorizeDoctor.exec,
appointmentController.updateAppointment.bind(appointmentController)
router.get("/doctor/details/:appointmentId", authorizeDoctor.exec, appointmentController.getAppointmentDetails);
router.get("/doctor", authorizeDoctor.exec, appointmentController.getAppointmentsDoctor);
router.put("/doctor/", authorizeDoctor.exec, appointmentController.updateAppointment
);


export default router;

export const webhook = appointmentController.handleStripeWebhook.bind(appointmentController);
export const webhook = appointmentController.handleStripeWebhook;
22 changes: 11 additions & 11 deletions server/src/presentation/routers/chat/ChatRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express from 'express';
import { Router } from 'express';
import ChatRepository from '../../../infrastructure/repositories/ChatRepository';
import MessageRepository from '../../../infrastructure/repositories/MessageRepository';
import PatientRepository from '../../../infrastructure/repositories/PatientRepository';
Expand All @@ -11,7 +11,7 @@ import JWTService from '../../../infrastructure/services/JWTService';
import PatientAuthMiddleware from '../../middlewares/PatientAuthMiddleware';
import DoctorAuthMiddleware from '../../middlewares/DoctorAuthMiddleware';

const router = express.Router();
const router = Router();

const validatorService = new JoiService();
const tokenService = new JWTService();
Expand All @@ -31,15 +31,15 @@ const chatController = new ChatController(createChatUseCase, getChatUseCase);
const authorizePatient = new PatientAuthMiddleware(tokenService);
const authorizeDoctor = new DoctorAuthMiddleware(tokenService);

router.get('/patient', authorizePatient.exec, chatController.getChatsOfPatient.bind(chatController));
router.post('/patient', authorizePatient.exec, chatController.createChatPatient.bind(chatController));
router.post('/patient/message', authorizePatient.exec, chatController.createMessagePatient.bind(chatController));
router.get('/patient/message/:chatId', authorizePatient.exec, chatController.getMessagesOfChatPatient.bind(chatController));
router.get('/patient', authorizePatient.exec, chatController.getChatsOfPatient);
router.post('/patient', authorizePatient.exec, chatController.createChatPatient);
router.post('/patient/message', authorizePatient.exec, chatController.createMessagePatient);
router.get('/patient/message/:chatId', authorizePatient.exec, chatController.getMessagesOfChatPatient);

router.get('/doctor', authorizeDoctor.exec, chatController.getChatsOfDoctor.bind(chatController));
router.get('/doctor/patients', authorizeDoctor.exec, chatController.getPatientsDoctor.bind(chatController));
router.get('/doctor/message/:chatId', authorizeDoctor.exec, chatController.getMessagesOfChatDoctor.bind(chatController));
router.post('/doctor', authorizeDoctor.exec, chatController.createChatDoctor.bind(chatController));
router.post('/doctor/message', authorizeDoctor.exec, chatController.createMessageDoctor.bind(chatController));
router.get('/doctor', authorizeDoctor.exec, chatController.getChatsOfDoctor);
router.get('/doctor/patients', authorizeDoctor.exec, chatController.getPatientsDoctor);
router.get('/doctor/message/:chatId', authorizeDoctor.exec, chatController.getMessagesOfChatDoctor);
router.post('/doctor', authorizeDoctor.exec, chatController.createChatDoctor);
router.post('/doctor/message', authorizeDoctor.exec, chatController.createMessageDoctor);

export default router;
4 changes: 2 additions & 2 deletions server/src/presentation/routers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express from "express";
import {Router} from "express";
import patientAuthentication from "./patient/AuthenticationRoutes";
import adminAuthentication from "./admin/AuthenticationRoutes";
import protectedRoutes from "./patient/PatientRoutes";
Expand All @@ -17,7 +17,7 @@ import notificationRoutes from "./notification/NotificationRoute";
import chatRouters from "./chat/ChatRoutes";
import videoSectionRoute from "./video/VideoSectionRoute";

const app = express();
const app = Router();
const tokenService = new TokenService();

const authorizePatient = new PatientAuthMiddleware(tokenService);
Expand Down
Loading

0 comments on commit 2306f1d

Please sign in to comment.