hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
182 stars 105 forks source link

[FEAT] API endpoint to Retrieve Authenticated User's Organisations - Backend #52

Closed ugberaeseac closed 2 weeks ago

ugberaeseac commented 1 month ago

Description

Implement a secure API endpoint to list all organizations associated with the authenticated user. Ensure the endpoint only returns the user's organizations and handles unauthorized and forbidden request errors properly.

Acceptance Criteria

Authentication

Fetch User Organisations

Successful Response

Endpoint:

[GET] /api/v1/organisations/me

Requests

GET /api/v1/organisations/me
Content-Type: application/json
Authorization: Bearer <access_token>

No request body or parameters required.

Successful Response

{
  "status": "success",
  "message": "Organizations retrieved successfully",
  "data": {
    "organisations": [
    {
        "orgId": "123e4567-e89b-12d3-a456-426614174000",
        "name": "Tech Innovators",
        "description": "A company focused on innovative tech solutions."
    },
    {
        "orgId": "123e4567-e89b-12d3-a456-426614174001",
        "name": "Health Solutions",
        "description": "Providing advanced healthcare services and products."
    }
    ]
  }
}

Error Response

401 Unauthorized

{
  "status":  "Unauthorized",
  "message":  "Unauthorized. Please log in."
  “status-code”: 401
}

403 Forbidden

{
  "status":  "Forbidden",
  "message":  "Forbidden. You are not authorized to access these organisations."
  “status-code”: 403
}

Purpose

Allow authenticated users to retrieve a list of organisations they created or belong to, therefore ensuring secure and accurate data retrieval.

Requirements

Expected Outcome

Testing:

Unit Tests:

Authentication Tests:

Authorization Tests:

markessien commented 1 month ago

This is not how it works

markessien commented 1 month ago

I have seen this before, check for duplication

ugberaeseac commented 1 month ago

Its obvious the other was done after ours was done because we are Issue #52 and the other is issue #154

Hardeezah commented 1 month ago

52 is earlier than yours, your last edit was 10 hours ago and mine was 13 hours ago

Screenshot from 2024-07-18 06-35-47

ugberaeseac commented 1 month ago

Sir, I don't think the features are similar. From my understanding, going by the endpoints

154: URL: /api/users/:user_id/organisations:

Implementing a feature whereas an authenticated user can view organisations any other user is associated with by providing their user id

52: [GET] /api/v1/organisations

implementing a feature where an authenticated user can only view the organisations they are associated with and takes no paramaters. It is similar to the endpoint /api/v1/organisations/me.

The logic is different, we can both start working on them?

Hardeezah commented 1 month ago

okay

ugberaeseac commented 1 month ago

@Hardeezah I advise you restructure your TITLE and also a bit of your description on #154 and i would edit #52 endpoint to " /api/v1/organisations/me"