-
Notifications
You must be signed in to change notification settings - Fork 0
Add Address Model and Routes #14
Copy link
Copy link
Open
Labels
Description
Description:
We need to integrate an address model into our existing Express API, including necessary routes for managing addresses. The address model will encompass various fields for detailed address management and should support specific access permissions as outlined below.
Address Model Properties:
-
CreatedBy- Type: ObjectId
- Description: Reference to the user who created the address.
- Example: ObjectId("60d21b4867d0d8992e610c86")
-
isDefault- Type: Boolean
- Description: Indicates whether the address is the default address for the user.
- Example: true
-
name- Type: String
- Description: Name or label for the address.
- Example: "Home"
-
contact- Type: Object
- Description: Contact information associated with the address.
email- Type: String
- Description: Email address associated with the address.
- Example: "user@example.com"
phone- Type: String
- Description: Phone number associated with the address.
- Example: "+1-555-555-5555"
-
address- Type: Object
- Description: Detailed address information.
doorNo- Type: String
- Description: Door number or apartment number.
- Example: "10A"
street- Type: String
- Description: Street name.
- Example: "Main St"
city- Type: String
- Description: City name.
- Example: "San Francisco"
state- Type: String
- Description: State name.
- Example: "CA"
zip- Type: String
- Description: ZIP 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]
-
additional instructions- Type: String
- Description: Any additional instructions related to the address.
- Example: "Ring the bell for entry."
Sample Address Model:
{
"CreatedBy": "60d21b4867d0d8992e610c86",
"isDefault": true,
"name": "Home",
"contact": {
"email": "user@example.com",
"phone": "+1-555-555-5555"
},
"address": {
"doorNo": "10A",
"street": "Main St",
"city": "San Francisco",
"state": "CA",
"zip": "94103",
"location": {
"type": "Point",
"coordinates": [-122.4194, 37.7749]
}
},
"additional instructions": "Ring the bell for entry."
}API Routes:
| HTTP Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /api/address | Get all addresses | Superadmin only |
| GET | /api/address/:id | Get address by ID | Superadmin and logged-in user only |
| GET | /api/address/user/:userId | Get all addresses by user ID | Superadmin and logged-in user only |
| GET | /api/address/default/:userId | Get default address by user ID | Superadmin and logged-in user only |
| POST | /api/address | Create a new address | Superadmin and logged-in user only |
| PUT | /api/address/:id | Update an address | Superadmin and logged-in user only |
| DELETE | /api/address/:id | Delete an address | Superadmin and logged-in user only |
Tasks:
- Define the address schema in the model.
- Implement the API routes for the address model.
- Integrate middleware for access control based on user roles.
- Conduct thorough testing to validate functionality and security of each route.
- Update the bruno with new routes
Checklist:
- Define the address schema in the model.
- Add
CreatedByfield. - Add
isDefaultfield. - Add
namefield. - Add
contactfield with nested properties (email,phone). - Add
addressfield with nested properties (doorNo,street,city,state,zip,location). - Add
additional instructionsfield.
- Add
- Implement GET /api/address route.
- Implement GET /api/address/:id route.
- Implement GET /api/address/user/:userId route.
- Implement GET /api/address/default/:userId route.
- Implement POST /api/address route.
- Implement PUT /api/address/:id route.
- Implement DELETE /api/address/:id route.
- Integrate middleware for access control based on user roles.
- Write comprehensive unit tests to ensure functionality and security.
Reactions are currently unavailable