Skip to content

Implement Region Management Routes #8

@nani-samireddy

Description

@nani-samireddy

We need to implement a set of API routes to manage regions in our application. Each region will have the following details:

  • name: The name of the region.
  • description: A brief description of the region.
  • createdBy: The user who created the region.
  • polygon: A list of location points that represent a polygon on the map.

Routes to be Implemented

Route Method Endpoint Input Response
Get All GET /api/region/ None Array of available regions
Get By ID GET /api/region/:id id as path parameter Single region details
Create POST /api/region/ name, description, polygon Message
Update By ID PUT /api/region/:id Fields to be updated Message
Delete By ID DELETE /api/region/:id None Message

Middleware for Authentication

  • All the above requests should only be allowed if a superadmin is logged in.
  • Create a middleware to check if the logged-in user is a superadmin.

Tasks

  1. Define Region Model: Update or create the Region model to include name, description, createdBy, and polygon.

  2. Implement Middleware: Create a middleware function to check if the logged-in user is a superadmin.

  3. Implement Routes:

    • getAll: Fetch and return an array of available regions.
    • getById: Fetch and return details of a single region by its ID.
    • create: Add a new region with the given details.
    • updateById: Update the details of an existing region by its ID.
    • deleteById: Delete a region by its ID.
  4. Add Routes to API Testing Tool: Add the new routes to the Bruno API testing tool for easy testing and verification.

  5. Testing: Write tests for each route to ensure they are working correctly and are properly secured with the middleware.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions