hngprojects / hng_boilerplate_expressjs

75 stars 83 forks source link

[FEAT]: Endpoint To Update Organization Details #146

Open oderahub opened 1 month ago

oderahub commented 1 month ago

Description Implement an API endpoint to allow authenticated users to update organization details.

Endpoint Feature

Acceptance Criteria

Request Example:

PUT /api/v1/organization/:organization_id

{
  "organization_id": "org_12345",
  "name": "New Organization Name",
  "email": "newemail@example.com",
  "industry": "Tech",
 "type": "Private",
  "country": "NGA",
  "address": "1234 New HNG",
  "state": "Lagos",
  "description": "A new description of the organization."
}

Response Example: On successful updating of the organization details, the API should return a 200 OK status code. The response body should contain a success message:


{
  "status": "success",
  "status_code": 200,
  "message": "Organization details updated successfully.",
  "data": {
    "organization_id": "org_12345",
    "name": "New Organization Name",
    "email": "newemail@example.com",
    "industry": "Tech",
    "type": "Private",
    "country": "NGA",
    "address": "1234 New HNG",
    "state": "Lagos",
    "description": "A new description of the organization."
  }
}

Data Validation Input Validation:

Confirm that organization_id, name, email, industry, type, country, address, state, and description are provided and valid. Example: If organization_id is invalid or missing, return a 422 status code with an error message.

{
  "status": "Error",
  "status_code": 422,
  "message": "Valid organization ID, name, email, industry, type, country, address, state, and description must be provided."
}

Output Validation:

If there is an error in updating the organization details (e.g., invalid database credentials, network issues), the API should return a 500 Internal Server Error status code with an appropriate message.

{
  "status": "Fail",
  "status_code": 500,
  "message": "Failed to update organization details. Please try again later."
}

Authentication and Authorization Authentication:

Authorization:

Edge Cases

Example: Handle scenarios where the database is temporarily unavailable. Handle case where the organization with organization_id is not found or no longer exists.

{
  "status": "unsuccessful",
  "status_code": 404,
  "message": "Organization with id 'org_12345' not found"
}

Performance and Security Performance Considerations:

Security Concerns:

Address security considerations such as data sanitization.

Unit Tests:

incredible-phoenix246 commented 1 month ago

First only the person that created the organization or the super admin can update the any settings on the organization

So update it