Skip to content

Response

When a use case is executed, it may return a response. This response can be a single object, a list of objects, or a paginated list of objects. To document the response, we create a response class that contains the properties of the response.

All API responses should have a corresponding response class if they need to return a body.

Example

INFO

make sure to use the ApiProperty decorator to generate OpenAPI documentation.

typescript
export class RoleResponse {
  @ApiProperty({ type: String, format: 'uuid' })
  uuid: string

  @ApiProperty()
  createdAt: Date

  @ApiProperty()
  updatedAt: Date

  @ApiProperty()
  name: string

  @ApiProperty({ enum: Permission, isArray: true })
  permissions: Permission[]

  constructor (role: Role) {
    this.uuid = role.uuid
    this.createdAt = role.createdAt
    this.updatedAt = role.updatedAt
    this.name = role.name
    this.permissions = role.permissions
  }
}