Files
MemeMind-Server/src/common/dto/api-response.dto.ts
richarjiang 6413d4f34c init
2026-03-15 11:35:39 +08:00

31 lines
834 B
TypeScript

import { ApiProperty } from '@nestjs/swagger';
export class ApiResponseDto<T> {
@ApiProperty({ description: '请求是否成功' })
success: boolean;
@ApiProperty({ description: '响应数据', nullable: true })
data: T | null;
@ApiProperty({ description: '错误信息', nullable: true })
message: string | null;
@ApiProperty({ description: '响应时间戳' })
timestamp: Date;
constructor(success: boolean, data: T | null, message: string | null = null) {
this.success = success;
this.data = data;
this.message = message;
this.timestamp = new Date();
}
static success<T>(data: T): ApiResponseDto<T> {
return new ApiResponseDto(true, data, null);
}
static error<T>(message: string): ApiResponseDto<T | null> {
return new ApiResponseDto<T | null>(false, null, message);
}
}