import { Response as ExpressResponse } from 'express';
import { assert } from 'console';
export function ErrorResponse(
res: ExpressResponse,
code: number,
errorMessage: string,
error?: unknown
) {
const response: ErrorResponseI = {
status: 'error',
message: errorMessage,
code: code,
error,
};
res.status(response.code).send(response);
}
export function SuccessResponse(
res: ExpressResponse,
code: number,
data: unknown,
message = 'Successful',
status = 'success'
) {
assert(code < 300, 'Success code must be less than 300');
const response: SuccessResponseI = {
status,
data,
message,
};
res.status(code).send(response);
}