add info endpoint

This commit is contained in:
rubikscraft
2022-03-12 15:36:01 +01:00
parent 903b20b32f
commit 0ad444f43b
10 changed files with 91 additions and 33 deletions

View File

@@ -0,0 +1,44 @@
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;