Add Payment Schema, Controllers, and Admin-Restricted Management Routes for Backend #954
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This PR introduces the schema, controller, and management features for handling payments in the backend. It includes a set of routes allowing the system to store, track, and manage payment-related information. Additionally, certain CRUD operations are restricted to admins, ensuring secure access and control over payment details via the admin dashboard.
Changes Implemented
1. Payment Schema
Payment
schema to store all relevant information about customer payments.paymentId
,orderId
,userId
,amount
,paymentMethod
,paymentStatus
,paymentDate
,transactionId
.paymentStatus
defaults toPending
.amount
,userId
, andorderId
to ensure data integrity.2. Payment Controller
paymentId
.paymentStatus
field (Pending, Completed, Failed).paymentId
.3. Payment Management API Endpoints
GET /
: Retrieve all payments (Admin-only).GET /:id
: Retrieve a specific payment by ID.GET /user/:userId
: Retrieve all payments made by a specific user.GET /status/:status
: Retrieve payments filtered by status.POST /
: Create a new payment.PATCH /:id/status
: Update the status of a specific payment (Admin-only).PATCH /:id/method
: Update the payment method of a specific payment (Admin-only).DELETE /:id
: Delete a specific payment (Admin-only).Additional Routes for Edge Cases:
GET /date-range
: Retrieve payments within a specific date range.GET /amount-range
: Retrieve payments within a specific amount range.GET /transaction/:transactionId
: Retrieve a payment by transaction ID.GET /count/status
: Count payments grouped by their status.4. Middleware
Access Control Middleware:
GET /
,PATCH /:id/status
,PATCH /:id/method
,DELETE /:id
) to admins only.Payment Data Validation Middleware: