Skip to content

Add Address Model and Routes #14

@nani-samireddy

Description

@nani-samireddy

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:

  1. CreatedBy

    • Type: ObjectId
    • Description: Reference to the user who created the address.
    • Example: ObjectId("60d21b4867d0d8992e610c86")
  2. isDefault

    • Type: Boolean
    • Description: Indicates whether the address is the default address for the user.
    • Example: true
  3. name

    • Type: String
    • Description: Name or label for the address.
    • Example: "Home"
  4. 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"
  5. 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]
  6. 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:

  1. Define the address schema in the model.
  2. Implement the API routes for the address model.
  3. Integrate middleware for access control based on user roles.
  4. Conduct thorough testing to validate functionality and security of each route.
  5. Update the bruno with new routes

Checklist:

  • Define the address schema in the model.
    • Add CreatedBy field.
    • Add isDefault field.
    • Add name field.
    • Add contact field with nested properties (email, phone).
    • Add address field with nested properties (doorNo, street, city, state, zip, location).
    • Add additional instructions field.
  • 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions