hngprojects / hng_boilerplate_expressjs

75 stars 83 forks source link

[FEAT]: Allow Super Admin to Update a Single User #149

Closed max-out-oluwadara closed 1 month ago

max-out-oluwadara commented 1 month ago

Description

Implement an API endpoint that allows authenticated super admins to update a single user's details. This endpoint ensures that only users with super admin privileges can modify user information, maintaining system security.

Endpoint Feature

Acceptance Criteria

Request Example:

METHOD: PATCH /api/v1/admin/users/fa9adebacde...

Header

Authorization: Bearer <access-token>
Content-Type: application/json

Body

{
"firstName": "New",
"lastName": "Name",
"email": "existinguser@example.com",
"role": "admin",
"password": "newPassword",
"isverified": true
}

Response Example:

json

{
"status": "success",
"status_code": 200,
"data": {
"user": {
"id": 1,
"name": "New Name",
"email": "existinguser@example.com",
"role": "admin",
"created_at": "2024-07-22T10:00:00Z",
"updated_at": "2024-07-23T12:00:00Z"
}
}
}

Data Validation

Input Validation:

Authentication and Authorization

Authentication:

Authorization:

Error Handling

Error Responses:

json

{
"status": "unsuccessful",
"status-code": 404,
"message": "User not found."
}

Edge Cases

  • Consider edge cases such as database connection issues or corrupted user data.
  • Example: Handle scenarios where the provided user details are invalid or incomplete.

Documentation

API Documentation:

Testing Requirements

Unit Tests:

Integration Tests:

Dependencies and Impact

Dependencies:

Impact Analysis:

AdeGneus commented 1 month ago
  1. Use kebab case for the request param
  2. The user-id is a UUID, not an integer.
  3. Input validation error should return a 422 status code

Format the issue nicely and you are good to go

max-out-oluwadara commented 1 month ago

@AdeGneus done pls recheck

AdeGneus commented 1 month ago

The endpoint should be something like this /api/v1/users/fa9adebacde. The UUID reference is its data type

max-out-oluwadara commented 1 month ago

@AdeGneus done