返回 AiToEarn
response.model.ts
根目录 / project / aitoearn-electron / server / src / common / model / response.model.ts
1 import { ApiProperty } from '@nestjs/swagger';
2
3 export class ResOp<T = any> {
4 @ApiProperty({ type: 'object', additionalProperties: true })
5 data?: T;
6
7 @ApiProperty({ type: 'number', default: 200 })
8 code: number;
9
10 @ApiProperty({ type: 'string', default: '请求成功' })
11 msg: string;
12
13 constructor(code: number, data: T, message = '请求成功') {
14 this.code = code;
15 this.data = data;
16 this.msg = message;
17 }
18
19 static success<T>(data?: T, message?: string) {
20 return new ResOp(200, data, message);
21 }
22
23 static error(code: number, message) {
24 return new ResOp(code, {}, message);
25 }
26 }
27
28 export class TreeResult<T> {
29 @ApiProperty()
30 id: number;
31
32 @ApiProperty()
33 parentId: number;
34
35 @ApiProperty()
36 children?: TreeResult<T>[];
37 }
38
38 lines TYPESCRIPT