I missed several important routes, services, and validators. Let me add the missing components to complete the backend structure.
Perfect! Now I've added all the missing components to complete your shelf coordination backend:
/api/branches) - Branch CRUD with proper authorization/api/markets) - Market management for admins/api/users) - User management with self-service endpoints/api/rtv) - RTV product management with barcode scanning/api/planogram) - Planogram submission with image uploadsGET /api/markets - Get all marketsPOST /api/markets - Create market (Admin)GET /api/markets/:id - Get specific marketPUT /api/markets/:id - Update market (Admin)DELETE /api/markets/:id - Delete market (Admin)GET /api/branches - Get all branchesPOST /api/branches - Create branch (Admin/Supervisor)GET /api/branches/:id - Get specific branchPUT /api/branches/:id - Update branch (Admin/Supervisor)DELETE /api/branches/:id - Delete branch (Admin)GET /api/users - Get all users (Admin/Supervisor)POST /api/users - Create user (Admin)GET /api/users/getMe - Get logged user dataPUT /api/users/updateMe - Update logged user dataPUT /api/users/changeMyPassword - Change logged user passwordPUT /api/users/:id/status - Update user status (Admin)GET /api/rtv - Get all RTV productsPOST /api/rtv - Create RTV product (Coordinator)POST /api/rtv/barcode - Add RTV by barcode (Coordinator)GET /api/rtv/:id - Get specific RTV productPUT /api/rtv/:id - Update RTV productDELETE /api/rtv/:id - Delete RTV productGET /api/planogram - Get all planogram submissionsPOST /api/planogram - Create planogram submission (Coordinator)GET /api/planogram/:id - Get specific submissionPUT /api/planogram/:id - Update submissionDELETE /api/planogram/:id - Delete submission (Admin/Supervisor)Now your backend is complete with all the missing components! The system supports the full workflow from organizational setup to task management, product handling, and specialized features like RTV and planogram validation.
I'll provide you with a comprehensive updated step-by-step guide to test your complete shelf coordination backend API using Postman, including all the new additions.
# Install dependencies
npm install
# Create uploads directory
mkdir uploads
# Start development server
npm run devSet Environment Variables:
baseUrl = http://localhost:8000authToken = (will be set after login)adminToken = (will be set after admin login)supervisorToken = (will be set after supervisor login)coordinatorToken = (will be set after coordinator login)POST {{baseUrl}}/api/auth/signupHeaders:
Content-Type: application/jsonBody (JSON):
{
"name": "System Admin",
"email": "admin@shelfapp.com",
"password": "123456",
"passwordConfirm": "123456",
"phone": "+201234567890",
"role": "admin"
}📝 Save the token as adminToken
POST {{baseUrl}}/api/auth/loginBody (JSON):
{
"email": "admin@shelfapp.com",
"password": "123456"
}POST {{baseUrl}}/api/marketsHeaders:
Authorization: Bearer {{adminToken}}
Content-Type: application/jsonBody (JSON):
{
"name": "Cairo Central Market"
}📝 Save the _id as marketId
{
"name": "Alexandria Market"
}{
"name": "Giza Market"
}GET {{baseUrl}}/api/marketsHeaders:
Authorization: Bearer {{adminToken}}POST {{baseUrl}}/api/branchesHeaders:
Authorization: Bearer {{adminToken}}
Content-Type: application/jsonBody (JSON):
{
"name": "Nasr City Branch",
"location": "Nasr City, Cairo, Egypt",
"marketId": "{{marketId}}"
}📝 Save the _id as branchId
{
"name": "Heliopolis Branch",
"location": "Heliopolis, Cairo, Egypt",
"marketId": "{{marketId}}"
}GET {{baseUrl}}/api/branchesQuery Parameters:
marketId: {marketId}page: 1limit: 10POST {{baseUrl}}/api/usersHeaders:
Authorization: Bearer {{adminToken}}
Content-Type: application/jsonBody (JSON):
{
"name": "Sarah Supervisor",
"email": "supervisor@shelfapp.com",
"password": "123456",
"phone": "+201234567891",
"role": "supervisor"
}📝 Save the _id as supervisorId
POST {{baseUrl}}/api/usersBody (JSON):
{
"name": "Ahmed Coordinator",
"email": "coordinator@shelfapp.com",
"password": "123456",
"phone": "+201234567892",
"role": "coordinator",
"branchId": "{{branchId}}"
}📝 Save the _id as coordinatorId
POST {{baseUrl}}/api/auth/loginBody (JSON):
{
"email": "supervisor@shelfapp.com",
"password": "123456"
}📝 Save token as supervisorToken
POST {{baseUrl}}/api/auth/loginBody (JSON):
{
"email": "coordinator@shelfapp.com",
"password": "123456"
}📝 Save token as coordinatorToken
GET {{baseUrl}}/api/usersHeaders:
Authorization: Bearer {{adminToken}}Query Parameters:
role: coordinatorstatus: activepage: 1limit: 10GET {{baseUrl}}/api/users/getMeHeaders:
Authorization: Bearer {{coordinatorToken}}PUT {{baseUrl}}/api/users/updateMeHeaders:
Authorization: Bearer {{coordinatorToken}}
Content-Type: application/jsonBody (JSON):
{
"name": "Ahmed Updated Coordinator",
"phone": "+201234567999"
}PUT {{baseUrl}}/api/users/{{coordinatorId}}/statusHeaders:
Authorization: Bearer {{adminToken}}
Content-Type: application/jsonBody (JSON):
{
"status": "suspended"
}POST {{baseUrl}}/api/productsHeaders:
Authorization: Bearer {{adminToken}}
Content-Type: application/jsonBody (JSON):
{
"name": "Coca Cola 330ml",
"barcode": "1234567890123",
"category": "Beverages",
"shelf": "A1-B2",
"stockQuantity": 50,
"availabilityStatus": "high"
}📝 Save the _id as productId1
{
"name": "Pepsi 330ml",
"barcode": "1234567890124",
"category": "Beverages",
"shelf": "A1-B3",
"stockQuantity": 30,
"availabilityStatus": "high"
}{
"name": "Lays Chips Original",
"barcode": "1234567890125",
"category": "Snacks",
"shelf": "B2-C1",
"stockQuantity": 5,
"availabilityStatus": "low"
}GET {{baseUrl}}/api/productsQuery Parameters:
category: BeveragesavailabilityStatus: highsearch: Cocapage: 1limit: 10GET {{baseUrl}}/api/products/barcode/1234567890123Headers:
Authorization: Bearer {{coordinatorToken}}POST {{baseUrl}}/api/tasksHeaders:
Authorization: Bearer {{supervisorToken}}
Content-Type: application/jsonBody (JSON):
{
"title": "Weekly Stock Check - Beverages",
"description": "Check stock levels for all beverage products in section A and update quantities",
"type": "StockCheck",
"branchId": "{{branchId}}",
"marketId": "{{marketId}}",
"assignedTo": "{{coordinatorId}}",
"scheduledDate": "2024-01-20T09:00:00.000Z"
}📝 Save the _id as taskId1
POST {{baseUrl}}/api/tasksBody (JSON):
{
"title": "Return Expired Products",
"description": "Identify and return all expired products to vendor",
"type": "RTV",
"branchId": "{{branchId}}",
"marketId": "{{marketId}}",
"assignedTo": "{{coordinatorId}}",
"scheduledDate": "2024-01-21T10:00:00.000Z"
}📝 Save the _id as rtvTaskId
POST {{baseUrl}}/api/tasksBody (JSON):
{
"title": "Planogram Compliance Check",
"description": "Verify product placement according to planogram guidelines",
"type": "Planogram",
"branchId": "{{branchId}}",
"marketId": "{{marketId}}",
"assignedTo": "{{coordinatorId}}",
"scheduledDate": "2024-01-22T11:00:00.000Z"
}📝 Save the _id as planogramTaskId
GET {{baseUrl}}/api/tasksHeaders:
Authorization: Bearer {{coordinatorToken}}Query Parameters:
status: pendingtype: StockCheckPUT {{baseUrl}}/api/tasks/{{taskId1}}Headers:
Authorization: Bearer {{coordinatorToken}}
Content-Type: application/jsonBody (JSON):
{
"status": "in-progress"
}PUT {{baseUrl}}/api/tasks/{{taskId1}}Body (JSON):
{
"status": "done"
}GET {{baseUrl}}/api/tasks/analyticsHeaders:
Authorization: Bearer {{supervisorToken}}POST {{baseUrl}}/api/rtvHeaders:
Authorization: Bearer {{coordinatorToken}}
Content-Type: application/jsonBody (JSON):
{
"productId": "{{productId1}}",
"taskId": "{{rtvTaskId}}",
"addedMethod": "manual",
"reason": "Product expired - expiry date 2024-01-15",
"quantity": 10
}POST {{baseUrl}}/api/rtv/barcodeHeaders:
Authorization: Bearer {{coordinatorToken}}
Content-Type: application/jsonBody (JSON):
{
"barcode": "1234567890124",
"taskId": "{{rtvTaskId}}",
"reason": "Damaged packaging during transport",
"quantity": 5
}GET {{baseUrl}}/api/rtvHeaders:
Authorization: Bearer {{coordinatorToken}}Query Parameters:
taskId: {rtvTaskId}addedMethod: barcodeGET {{baseUrl}}/api/rtv/{{rtvId}}PUT {{baseUrl}}/api/rtv/{{rtvId}}Body (JSON):
{
"reason": "Updated: Product expired and damaged packaging",
"quantity": 12
}POST {{baseUrl}}/api/planogramHeaders:
Authorization: Bearer {{coordinatorToken}}
Content-Type: multipart/form-dataBody (Form-data):
taskId: {planogramTaskId}notes: Initial planogram setup for beverages sectionimageBefore: [Upload image file - before.jpg]imageAfter: [Upload image file - after.jpg]GET {{baseUrl}}/api/planogramHeaders:
Authorization: Bearer {{supervisorToken}}GET {{baseUrl}}/api/planogram/{{planogramId}}PUT {{baseUrl}}/api/planogram/{{planogramId}}Body (JSON):
{
"notes": "Updated notes: Compliance achieved after adjustments"
}POST {{baseUrl}}/api/offersHeaders:
Authorization: Bearer {{coordinatorToken}}
Content-Type: multipart/form-dataBody (Form-data):
productId: {productId1}details: Special weekend discount - Buy 2 Get 1 Freeprice: 25.99image: [Upload image file - offer.jpg]GET {{baseUrl}}/api/offersHeaders:
Authorization: Bearer {{adminToken}}Query Parameters:
status: pendingPUT {{baseUrl}}/api/offers/{{offerId}}/statusHeaders:
Authorization: Bearer {{adminToken}}
Content-Type: application/jsonBody (JSON):
{
"status": "approved"
}PUT {{baseUrl}}/api/offers/{{offerId}}/statusBody (JSON):
{
"status": "rejected"
}Step 1: Login as Supervisor
POST {{baseUrl}}/api/auth/loginStep 2: Create Task
POST {{baseUrl}}/api/tasksStep 3: Login as Coordinator
POST {{baseUrl}}/api/auth/loginStep 4: View Assigned Tasks
GET {{baseUrl}}/api/tasksStep 5: Start Task
PUT {{baseUrl}}/api/tasks/{{taskId}}{
"status": "in-progress"
}Step 6: Complete Task with Attachments
PUT {{baseUrl}}/api/tasks/{{taskId}}Form-data:
status: doneattachments: [Upload files]Test 1: Try accessing admin route with coordinator token (Should fail)
GET {{baseUrl}}/api/users
Authorization: Bearer {{coordinatorToken}}Expected Response:
{
"message": "You are not allowed to access this route"
}Test 2: Try accessing other user's tasks (Should fail)
GET {{baseUrl}}/api/tasks/{{otherUserTaskId}}
Authorization: Bearer {{coordinatorToken}}Step 1: Forgot Password
POST {{baseUrl}}/api/auth/forgotPassword{
"email": "coordinator@shelfapp.com"
}Step 2: Check email for reset code, then verify
POST {{baseUrl}}/api/auth/verifyResetCode{
"resetCode": "123456"
}Step 3: Reset Password
PUT {{baseUrl}}/api/auth/resetPassword{
"email": "coordinator@shelfapp.com",
"newPassword": "newpassword123"
}| Variable | Value | Description |
|---|---|---|
| baseUrl | http://localhost:8000 | Base API URL |
| adminToken | Bearer TOKEN | Admin authentication token |
| supervisorToken | Bearer TOKEN | Supervisor authentication token |
| coordinatorToken | Bearer TOKEN | Coordinator authentication token |
| marketId | MARKET_ID | Created market ID |
| branchId | BRANCH_ID | Created branch ID |
| supervisorId | USER_ID | Supervisor user ID |
| coordinatorId | USER_ID | Coordinator user ID |
| productId1 | PRODUCT_ID | First product ID |
| taskId1 | TASK_ID | First task ID |
| rtvTaskId | TASK_ID | RTV task ID |
| planogramTaskId | TASK_ID | Planogram task ID |
{
"message": "Only Images allowed"
}Solution: Ensure you're uploading image files (jpg, png, gif)
{
"errors": [
{
"msg": "Invalid market ID format"
}
]
}Solution: Use valid MongoDB ObjectId for marketId
{
"errors": [
{
"msg": "Branch ID required for coordinator role"
}
]
}Solution: Always provide branchId when creating coordinators
{
"message": "Task can only be assigned to coordinators"
}Solution: Ensure assignedTo field contains a coordinator's user ID
This comprehensive testing guide covers all the new features and ensures your complete shelf coordination backend is working perfectly! Start with Phase 1 and work through each phase systematically.
You can send messages while the preview loads