Skip to content

Update User

Method

REST method is adopted.

HTTP Method

PUT: Update user details

Naming Convention

To unify naming of query parameters and nodes and improve readability, snake_case is used for URIs and nodes in JSON during requests.

Request and Response

Headers

Meta information is set in HTTP headers rather than in the response body.

Request Headers

  • Authorization: Bearer <access_token>
  • Content-Type: application/json

Response Headers

  • Content-Type: application/json

Update User

URI

Path parameter type is integer.

/api/v1/users/{user_id}

Request Body

Request body is JSON. All fields are optional โ€” only included fields will be updated.

{
  "name": "Updated Name",
  "organizationId": 2
}

Validation Rules

Field Rule
name Optional. 1-255 characters.
organizationId Optional. Must be a positive integer.

Response (200 OK)

Response is JSON.

{
  "id": 1,
  "cognitoSub": "1111-aaaa-2222-bbbb",
  "organizationId": 2,
  "name": "Updated Name",
  "createdAt": 1640995200000,
  "updatedAt": 1640995200000,
  "createdBy": "1111-aaaa-2222-bbbb",
  "updatedBy": "1111-aaaa-2222-bbbb",
  "deletedAt": null,
  "deletedBy": null
}

Authentication

Authentication is performed using JSON Web Tokens (JWT) issued by Amazon Cognito. A valid Bearer token is required in the Authorization header.

Exception Handling

Exception handling status codes are as follows.

Description Status Code Status Name
Missing or invalid token 401 Unauthorized
User not found 404 Not Found
Internal server error 500 Internal Server Error

Process Flow

Sequence Diagram

sequenceDiagram
    participant Client
    participant Middleware as Protected Route Middleware
    participant API as Hono Router
    participant Service as User Service
    participant DB as PostgreSQL Database

    Client->>Middleware: PUT /api/v1/users/{user_id}
    Middleware->>Middleware: Verify JWT & session

    alt Token Valid
        Middleware-->>API: Auth info (sub)
        API->>Service: update(id, { name, organizationId, actorSub })
        Service->>DB: Update user record
        DB-->>Service: Updated user record
        Service-->>API: User with relations
        API-->>Client: 200 OK
    else Token Invalid
        Middleware-->>Client: 401 Unauthorized
    end

Routes Layer

API routing is performed here. The protectedRoute middleware validates the JWT token. The handler validates the request body and user_id path parameter via Zod schema, extracts the actor's Cognito sub, and delegates to the user service.

Source: apps/admin/src/routes/v1/user.ts

Services Layer

This section describes business logic. It updates the user record with the provided fields, recording the actor's Cognito sub as the updater.

Source: apps/admin/src/services/user.ts

Repositories Layer

This section describes access to databases. It handles partial updates of user records.

Source: apps/admin/src/repositories/user.ts

Security

  • Token validated by protectedRoute middleware before handler execution
  • Actor's Cognito sub recorded as updatedBy for audit trail