Skip to content

BaseReqDto Basic Request Data Transfer Object

BaseReqDtois a basic request data transfer object (DTO) used to standardize the structure of request objects throughout the application. It contains common basic fields that are often used to track the status of an entity, create and update information.

Field description

Column NameTypeDescriptionVerificationNotes
remarkstringNotesOptional, stringAdditional instructions for storing entities
statusnumberStatus valueOptional, numberIndicates the current status of the entity
isDeletednumberWhether to delete the tagOptional, numberUsed for soft deletion function, 0 means not deleted, 1 means deleted
creatorstringCreate person IDOptional, convert through BigIntRecord the user ID that created the entity
createTimeDateCreate timeOptional, date stringRecording the timestamp created by the entity
updaterstringUpdater IDOptional, convert through BigIntRecord the user ID that was last updated on the entity
updateTimeDateUpdate timeOptional, date stringRecord the last updated time stamp of the entity
multilingualFieldsstring[]Multilingual column listOptional, arrayOnly used when front-end query enables multilingual function

Disable the editing bar

The system defines a set of columns that prohibit direct editing, which are usually automatically managed by the system:

typescript
export const disableEditFields = ['isDeleted', 'creator', 'createTime', 'updater', 'updateTime'] as const

These fields should not be modified in general update operations, but should be automatically maintained by the system.

How to use

Inherited use

Other DTO classes can be inheritedBaseReqDtoTo get these basic fields:

typescript
import { BaseReqDto } from '@/common/dtos/base.req.dto'

export class UserDto extends BaseReqDto {
  @ApiProperty({ description: '使用者名稱' })
  @IsString()
  username: string

  // 其他特定欄位...
}

Multilingual support

When the current query requires multilingual support, it can be included in the request.multilingualFieldsColumns, specify which columns require multilingual processing:

json
// 前端請求範例
{
  "status": 1,
  "multilingualFields": ["title", "description"]
}

Data Verification

BaseReqDtouseclass-validatorandclass-transformerPerform data verification and conversion:

  • All fields are marked as@IsOptional(), means that it can be omitted in the request
  • A specific type of field uses the corresponding verification decorator, such as@IsString()@IsNumber()@IsDateString()
  • creatorandupdaterUse custom fieldsParseBigIntPipeConvert to support large integer IDs

Swagger Files

All fields are used@ApiProperty()The decorator has added a description to display relevant information in the Swagger API file.