mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-11-14 07:45:39 +01:00
45 lines
730 B
TypeScript
45 lines
730 B
TypeScript
|
|
import {
|
||
|
|
IsBoolean,
|
||
|
|
IsDefined,
|
||
|
|
IsInt,
|
||
|
|
IsNotEmpty,
|
||
|
|
IsString,
|
||
|
|
Max,
|
||
|
|
Min,
|
||
|
|
ValidateNested,
|
||
|
|
} from 'class-validator';
|
||
|
|
|
||
|
|
class BaseApiResponse<T extends Object, W extends boolean> {
|
||
|
|
@IsBoolean()
|
||
|
|
@IsDefined()
|
||
|
|
success: W;
|
||
|
|
|
||
|
|
@IsInt()
|
||
|
|
@Min(0)
|
||
|
|
@Max(1000)
|
||
|
|
@IsDefined()
|
||
|
|
statusCode: number;
|
||
|
|
|
||
|
|
@IsString()
|
||
|
|
@IsNotEmpty()
|
||
|
|
timestamp: string;
|
||
|
|
|
||
|
|
@ValidateNested()
|
||
|
|
@IsDefined()
|
||
|
|
data: T;
|
||
|
|
}
|
||
|
|
|
||
|
|
export class ApiSuccessResponse<T extends Object> extends BaseApiResponse<
|
||
|
|
T,
|
||
|
|
true
|
||
|
|
> {}
|
||
|
|
|
||
|
|
export class ApiErrorData {
|
||
|
|
@IsString()
|
||
|
|
@IsNotEmpty()
|
||
|
|
message: string;
|
||
|
|
}
|
||
|
|
export class ApiErrorResponse extends BaseApiResponse<ApiErrorData, false> {}
|
||
|
|
|
||
|
|
export type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;
|