-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Description:
We need to add routes for managing store data in our existing Express API. The store object will have the following properties, and the routes will have specific access permissions as outlined below.
Store Object Properties:
-
name- Type: String
- Description: Name of the store
- Example: "The Great Bakery"
-
description- Type: String
- Description: Description of the store
- Example: "A cozy bakery specializing in artisan bread and pastries."
-
logo- Type: String
- Description: URL to the store's logo
- Example: "https://example.com/images/logo.png"
-
banner- Type: String
- Description: URL to the store's banner image
- Example: "https://example.com/images/banner.png"
-
region_id- Type: ObjectId
- Description: Reference to the region where the store is located
- Example: ObjectId("60d21b4667d0d8992e610c85")
-
status- Type: String
- Description: Current status of the store
- Values: "active", "inactive", "deleted", "pending", "suspended"
- Example: "pending"
-
address- Type: Object
- Description: Address details of the store
street- Type: String
- Description: Street address
- Example: "123 Main St"
city- Type: String
- Description: City
- Example: "San Francisco"
state- Type: String
- Description: State
- Example: "CA"
postal_code- Type: String
- Description: Postal code
- Example: "94103"
location- Type: Object
- Description: Geographical location
type- Type: String
- Description: Type of the geographical data, should be "Point"
- Example: "Point"
coordinates- Type: Array
- Description: Coordinates of the location [longitude, latitude]
- Example: [-122.4194, 37.7749]
-
contact- Type: Object
- Description: Contact information of the store
phone- Type: String
- Description: Phone number
- Example: "+1-555-555-5555"
email- Type: String
- Description: Email address
- Example: "contact@example.com"
website- Type: String
- Description: Website URL
- Example: "https://example.com"
-
working_hours- Type: Object
- Description: Working hours of the store for each day of the week
monday- Type: Object
- Description: Opening and closing times
- Example: {"open": "08:00", "close": "20:00"}
tuesday- Type: Object
- Description: Opening and closing times
- Example: {"open": "08:00", "close": "20:00"}
wednesday- Type: Object
- Description: Opening and closing times
- Example: {"open": "08:00", "close": "20:00"}
thursday- Type: Object
- Description: Opening and closing times
- Example: {"open": "08:00", "close": "20:00"}
friday- Type: Object
- Description: Opening and closing times
- Example: {"open": "08:00", "close": "22:00"}
saturday- Type: Object
- Description: Opening and closing times
- Example: {"open": "08:00", "close": "22:00"}
sunday- Type: Object
- Description: Opening and closing times
- Example: {"open": "10:00", "close": "18:00"}
-
createdBy
- Type: ObjectId
- Description: Reference to the sudouser who created this store
- Example: ObjectId("60d21b4667d0d8992e610c85")
API Routes and Access Permissions:
| HTTP Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /api/store/ | Returns all stores | Superadmin (1) |
| GET | /api/store/:id | Returns a single store | Superadmin and Store Owner (1, 3) |
| GET | /api/store/region/:region_id | Returns all stores in a region | Superadmin (1) |
| GET | /api/store/store/:creator_id | Returns all stores created by a user | Superadmin and Store Owner (1, 3) |
| POST | /api/store/ | Creates a new store | Superadmin and Creator (1, 3) |
| PUT | /api/store/:id | Updates a store | Superadmin and Creator (1, 3) |
| PUT | /api/store/:id/status | Updates the status of a store | Superadmin (1) |
| DELETE | /api/store/:id | Deletes a store | Superadmin and Creator (1, 3) |
Access Notes:
- The store owner can only access the stores they have created.
- When a store is created, the status should be
pendingand the superadmin should change the status toactiveorinactive. - When a store is deleted, the status should be
deleted. - When a store is suspended, the status should be
suspended. - When a store is pending, the status should be
pending. - When a store is active, the status should be
active. - When a store is inactive, the status should be
inactive.
Tasks:
- Define the store schema in the model.
- Implement the API routes with the specified access permissions.
- Add middleware for access control based on user roles.
- Implement status change logic according to the specified rules.
- Write tests to verify the functionality of each route and status change.
Checklist:
- Define the store schema in the model
- Implement GET /api/store/ route
- Implement GET /api/store/:id route
- Implement GET /api/store/region/:region_id route
- Implement GET /api/store/store/:creator_id route
- Implement POST /api/store/ route
- Implement PUT /api/store/:id route
- Implement PUT /api/store/:id/status route
- Implement DELETE /api/store/:id route
- Add middleware for access control based on user roles
- Implement status change logic according to the specified rules
- Write tests to verify the functionality of each route and status change
Reactions are currently unavailable