Skip to content

Commit

Permalink
Merge pull request hngprojects#408 from aniebietafia/feat/documentati…
Browse files Browse the repository at this point in the history
…on-changes-for-update-user-profile

refactor: updated documentation for update user endpoint
  • Loading branch information
PreciousIfeaka authored Aug 1, 2024
2 parents f540af9 + 04a59e3 commit d2c3c39
Showing 1 changed file with 118 additions and 106 deletions.
224 changes: 118 additions & 106 deletions src/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,130 +300,142 @@ class UserController {

/**
* @swagger
* /api/v1/users/{id}:
* patch:
* tags:
* - User
* summary: SuperAdmin- Update a user
* description: 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.
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: The ID of the user to update
* requestBody:
* /api/v1/user/{id}:
* put:
* tags:
* - User
* summary: Update User Profile
* description: Update the profile of a user
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: The ID of the user
* requestBody:
* required: true
* content:
* multipart/form-data:
* schema:
* type: object
* properties:
* avatarUrl:
* type: string
* format: binary
* description: The user's profile picture
* application/json:
* schema:
* type: object
* properties:
* first_name:
* type: string
* example: John
* last_name:
* type: string
* example: Doe
* phone_number:
* type: string
* example: 08012345678
* responses:
* 200:
* description: User profile updated successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* firstName:
* id:
* type: string
* example: New
* lastName:
* example: 315e0834-e96d-4ddc-9974-726e8c1e9cf9
* name:
* type: string
* example: John Doe
* email:
* type: string
* role:
* type: string
* password:
* example: [email protected]
* google_id:
* type: string
* example: null
* isVerified:
* type: boolean
* example: true
* responses:
* 200:
* description: Successfully updated the user
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: success
* status_code:
* type: integer
* example: 200
* data:
* type: object
* properties:
* id:
* type: string
* email:
* type: string
* role:
* type: string
* created_at:
* type: string
* format: date-time
* updated_at:
* type: string
* format: date-time
* 422:
* description: Validation error
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: Error
* status_code:
* type: integer
* example: 422
* message:
* type: string
* example: "Invalid user details provided."
* 403:
* description: Access denied
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: Error
* status_code:
* type: integer
* example: 403
* message:
* type: string
* example: "Access denied. Super admin privileges required."
* 404:
* description: User not found
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: unsuccessful
* status_code:
* type: integer
* example: 404
* message:
* type: string
* example: "User with id '123' not found"
* 500:
* description: Server Error
* role:
* type: string
* example: user
* profile:
* type: object
* properties:
* id:
* type: string
* example: 315e0834-e96d-4ddc-9974-726e8c1e9cf9
* first_name:
* type: string
* example: John
* last_name:
* type: string
* example: Doe
* phone_number:
* type: string
* example: 08012345678
* avatarUrl:
* type: string
* example: https://avatar.com/avatar.png
* 400:
* description: Bad request
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: unsuccessful
* status_code:
* type: integer
* example: 400
* message:
* type: string
* example: Valid id must be provided
* 404:
* description: Not found
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: unsuccessful
* status_code:
* type: integer
* example: 404
* message:
* type: string
* example: User not found
* 500:
* description: Server Error
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: unsuccessful
* status_code:
* type: integer
* example: 500
* message:
* type: string
* example: Internal Server Error
*/

public async updateUserProfile(req: Request, res: Response) {
try {
const user = await this.userService.updateUserProfile(
req.params.id,
req.body,
req.file,
);
const user = await this.userService.updateUserProfile(req.params.id, req.body, req.file);
res.status(200).json(user);
} catch (error) {
if (error instanceof HttpError) {
Expand Down

0 comments on commit d2c3c39

Please sign in to comment.