Issue: Create API to Fetch Requests Optimally
Description
Develop a new API endpoint to optimally fetch requests, using logic based on the existing fetchUserRequests function. The new function should be named fetchUserRequestsOptimal. It must include pagination (5 items per page) and support filtering via query parameters.
Requirements
- Function Name:
fetchUserRequestsOptimal
- API Endpoint:
/api/request/user-get/optimal/:id
- HTTP Method:
GET
Query Parameters
| Parameter |
Type |
Required |
Description |
page |
Number |
No |
Page number for pagination (default: 1) |
status |
String |
No |
Filter by request status (e.g., pending, approved) |
products |
String |
No |
Filter by product(s). Accepts comma-separated values. |
Pagination
- Page size is fixed to 5 requests per page.
Response
The API should return a JSON object containing:
data: List of requests matching the filters
pagination:
totalRequests: Total number of matching requests
totalPages: Total pages available
currentPage: Current page number
filtersApplied: An object showing active filters (if any)
Example Successful Response
{
"data": [
{
"id": "REQ123",
"status": "approved",
"products": ["productA"]
},
...
],
"pagination": {
"totalRequests": 17,
"totalPages": 4,
"currentPage": 2
},
"filtersApplied": {
"status": "approved",
"products": ["productA", "productB"]
}
}
Issue: Create API to Fetch Requests Optimally
Description
Develop a new API endpoint to optimally fetch requests, using logic based on the existing
fetchUserRequestsfunction. The new function should be namedfetchUserRequestsOptimal. It must include pagination (5 items per page) and support filtering via query parameters.Requirements
fetchUserRequestsOptimal/api/request/user-get/optimal/:idGETQuery Parameters
pagestatuspending,approved)productsPagination
Response
The API should return a JSON object containing:
data: List of requests matching the filterspagination:totalRequests: Total number of matching requeststotalPages: Total pages availablecurrentPage: Current page numberfiltersApplied: An object showing active filters (if any)Example Successful Response
{ "data": [ { "id": "REQ123", "status": "approved", "products": ["productA"] }, ... ], "pagination": { "totalRequests": 17, "totalPages": 4, "currentPage": 2 }, "filtersApplied": { "status": "approved", "products": ["productA", "productB"] } }