From 342be40c01d9499036fb94a6167a6e6c7c3bfb6b Mon Sep 17 00:00:00 2001 From: Sinan Date: Mon, 16 Sep 2024 16:57:47 +0530 Subject: [PATCH] inital serer setup completed for payment --- .../infrastructure/database/AppointmentModel.ts | 7 ++++--- server/src/infrastructure/database/PaymentModel.ts | 2 -- .../src/presentation/middlewares/ErrorHandler.ts | 3 --- .../routers/appointment/AppointmentRoutes.ts | 2 +- .../src/use_case/appointment/AppointmentUseCase.ts | 14 ++++++++------ 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/server/src/infrastructure/database/AppointmentModel.ts b/server/src/infrastructure/database/AppointmentModel.ts index 06ebf83d..42c5ddd5 100644 --- a/server/src/infrastructure/database/AppointmentModel.ts +++ b/server/src/infrastructure/database/AppointmentModel.ts @@ -45,9 +45,10 @@ const appointmentSchema = new Schema( required: true, }, paymentId:{ - type:String, - required:true, - default:null + type: Schema.Types.ObjectId, + ref: 'Payment', + required: true, + index: true, } }, { diff --git a/server/src/infrastructure/database/PaymentModel.ts b/server/src/infrastructure/database/PaymentModel.ts index 7ff2724e..a6f821a3 100644 --- a/server/src/infrastructure/database/PaymentModel.ts +++ b/server/src/infrastructure/database/PaymentModel.ts @@ -5,7 +5,6 @@ const paymentSchema = new Schema( { orderId: { type: String, - required: true, }, paymentId: { type: String, @@ -14,7 +13,6 @@ const paymentSchema = new Schema( appointmentId: { type: Schema.Types.ObjectId, ref: 'Appointment', - required: true, index: true, }, amount: { diff --git a/server/src/presentation/middlewares/ErrorHandler.ts b/server/src/presentation/middlewares/ErrorHandler.ts index 0d311a89..8fb40f74 100644 --- a/server/src/presentation/middlewares/ErrorHandler.ts +++ b/server/src/presentation/middlewares/ErrorHandler.ts @@ -25,7 +25,6 @@ export default class ErrorHandler { method: req.method, path: req.path, clientIp, - requestHeaders: req.headers, error: message, }); return res.status(StatusCode.Conflict).json({ @@ -43,7 +42,6 @@ export default class ErrorHandler { method: req.method, path: req.path, clientIp, - requestHeaders: req.headers, }); return res.status(StatusCode.InternalServerError).json({ message: "We are having an issue with the Email Service.", @@ -55,7 +53,6 @@ export default class ErrorHandler { method: req.method, path: req.path, clientIp, - requestHeaders: req.headers, stack: error.stack, }); diff --git a/server/src/presentation/routers/appointment/AppointmentRoutes.ts b/server/src/presentation/routers/appointment/AppointmentRoutes.ts index 91f8a927..4632f901 100644 --- a/server/src/presentation/routers/appointment/AppointmentRoutes.ts +++ b/server/src/presentation/routers/appointment/AppointmentRoutes.ts @@ -26,6 +26,6 @@ const appointmentController = new AppointmentController(appointmentUseCase); const authorizePatient = new PatientAuthMiddleware(tokenService); router.post('/', authorizePatient.exec.bind(authorizePatient), appointmentController.create.bind(appointmentController)); -router.put('/payment', authorizePatient.exec.bind(authorizePatient), appointmentController.completePayment.bind(appointmentController)) +router.post('/verify-payment', authorizePatient.exec.bind(authorizePatient), appointmentController.completePayment.bind(appointmentController)) export default router; \ No newline at end of file diff --git a/server/src/use_case/appointment/AppointmentUseCase.ts b/server/src/use_case/appointment/AppointmentUseCase.ts index 9e0c5c21..f854d145 100644 --- a/server/src/use_case/appointment/AppointmentUseCase.ts +++ b/server/src/use_case/appointment/AppointmentUseCase.ts @@ -48,18 +48,20 @@ export default class AppointmentUseCase { const razorpayOrder = await this.paymentService.createOrder(this.bookingAmount, 'INR', `receipt_${payment._id}`); - await this.paymentRepository.update({ - _id: payment._id, - orderId: razorpayOrder.id!, - }); - + const appointmentId = await this.appointmentRepository.create({ ...appointmentData, patientId, status: AppointmentStatus.PAYMENT_PENDING, - paymentId: razorpayOrder.id!, + paymentId: payment._id!, }); + await this.paymentRepository.update({ + _id: payment._id, + orderId: razorpayOrder.id!, + appointmentId + }); + return { orderId: razorpayOrder.id, appointmentId }; }