2022-02-25 12:22:00 +01:00
|
|
|
import {
|
2022-04-02 23:25:49 +02:00
|
|
|
IsBoolean, IsInt,
|
2022-02-25 12:22:00 +01:00
|
|
|
IsNotEmpty,
|
|
|
|
|
IsString,
|
|
|
|
|
Max,
|
2022-03-19 21:34:33 +01:00
|
|
|
Min
|
2022-02-25 12:22:00 +01:00
|
|
|
} from 'class-validator';
|
|
|
|
|
|
|
|
|
|
class BaseApiResponse<T extends Object, W extends boolean> {
|
|
|
|
|
@IsBoolean()
|
|
|
|
|
success: W;
|
|
|
|
|
|
|
|
|
|
@IsInt()
|
|
|
|
|
@Min(0)
|
|
|
|
|
@Max(1000)
|
|
|
|
|
statusCode: number;
|
|
|
|
|
|
|
|
|
|
@IsString()
|
|
|
|
|
timestamp: string;
|
|
|
|
|
|
2022-04-02 23:25:49 +02:00
|
|
|
@IsNotEmpty()
|
2022-02-25 12:22:00 +01:00
|
|
|
data: T;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ApiSuccessResponse<T extends Object> extends BaseApiResponse<
|
|
|
|
|
T,
|
|
|
|
|
true
|
|
|
|
|
> {}
|
|
|
|
|
|
|
|
|
|
export class ApiErrorData {
|
|
|
|
|
@IsString()
|
|
|
|
|
message: string;
|
|
|
|
|
}
|
|
|
|
|
export class ApiErrorResponse extends BaseApiResponse<ApiErrorData, false> {}
|
|
|
|
|
|
|
|
|
|
export type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;
|