backend/lib/seed/interfaces/response.ts
2025-05-14 21:45:16 +02:00

29 lines
695 B
TypeScript

import { Field, ObjectType } from 'type-graphql';
export interface ErrorResponse {
statusCode: 400 | 403 | 404 | 500;
body: string;
[k: string]: any;
}
@ObjectType()
export class SuccessResponse {
@Field()
success: boolean;
}
export interface FunctionResponse<T = any> {
success: boolean;
message: string;
data: T;
}
export const fError = (message: string, data?: any): FunctionResponse<typeof data> => {
console.error(message, data);
return { success: false, message: message, data };
};
export const fSuccess = (data?: any, message?: string): FunctionResponse<typeof data> => {
return { success: true, message: message || 'success', data };
};