Skip to content

Commit

Permalink
inital serer setup completed for payment
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Sep 16, 2024
1 parent aabb4b8 commit 342be40
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
7 changes: 4 additions & 3 deletions server/src/infrastructure/database/AppointmentModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ const appointmentSchema = new Schema<IAppointment>(
required: true,
},
paymentId:{
type:String,
required:true,
default:null
type: Schema.Types.ObjectId,
ref: 'Payment',
required: true,
index: true,
}
},
{
Expand Down
2 changes: 0 additions & 2 deletions server/src/infrastructure/database/PaymentModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const paymentSchema = new Schema<IPayment>(
{
orderId: {
type: String,
required: true,
},
paymentId: {
type: String,
Expand All @@ -14,7 +13,6 @@ const paymentSchema = new Schema<IPayment>(
appointmentId: {
type: Schema.Types.ObjectId,
ref: 'Appointment',
required: true,
index: true,
},
amount: {
Expand Down
3 changes: 0 additions & 3 deletions server/src/presentation/middlewares/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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.",
Expand All @@ -55,7 +53,6 @@ export default class ErrorHandler {
method: req.method,
path: req.path,
clientIp,
requestHeaders: req.headers,
stack: error.stack,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 8 additions & 6 deletions server/src/use_case/appointment/AppointmentUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down

1 comment on commit 342be40

@vercel
Copy link

@vercel vercel bot commented on 342be40 Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.