UNPKG

axiodb

Version:

The Pure JavaScript Alternative to SQLite. Embedded NoSQL database for Node.js with MongoDB-style queries, zero native dependencies, built-in InMemoryCache, and web GUI. Perfect for desktop apps, CLI tools, and embedded systems. No compilation, no platfor

57 lines (56 loc) 2.11 kB
import { ErrorInterface, SuccessInterface } from "../config/Interfaces/Helper/response.helper.interface"; /** * @class ResponseHelper * @description A helper class to standardize API responses. * * @property {number} SucessCode - The HTTP status code for a successful response. * @property {number} ErrorCode - The HTTP status code for an error response. * * @constructor * Initializes the ResponseHelper with default status codes. * * @method Success * @async * @param {any} [data] - Optional data to include in the success response. * @returns {Promise<SuccessInterface>} A promise that resolves to a success response object. * * @method Error * @async * @param {string} [message] - Optional error message to include in the error response. * @returns {Promise<ErrorInterface>} A promise that resolves to an error response object. */ /** * A helper class for generating standardized success and error response objects. * * @remarks * This class provides methods to generate success and error responses with predefined status codes. * It uses the `StatusCodes` enumeration to set the HTTP status codes for success and error responses. * * @example * ```typescript * const responseHelper = new ResponseHelper(); * const successResponse = await responseHelper.Success({ key: 'value' }); * const errorResponse = await responseHelper.Error('An error occurred'); * ``` * * @public */ export default class ResponseHelper { private SucessCode; private ErrorCode; constructor(); /** * Generates a success response object. * * @param data - Optional data to include in the success response. * @returns A promise that resolves to a success response object implementing the SuccessInterface. */ Success(data?: any): Promise<SuccessInterface>; /** * Generates an error response object. * * @param {string} [message] - Optional error message to include in the response. * @returns {Promise<ErrorInterface>} A promise that resolves to an error response object. */ Error(message?: any): Promise<ErrorInterface>; }