mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-11-17 00:30:37 +01:00
add info endpoint
This commit is contained in:
44
shared/src/dto/api/api.dto.ts
Normal file
44
shared/src/dto/api/api.dto.ts
Normal 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;
|
||||
Reference in New Issue
Block a user