"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PRAS = void 0; class PRAS { getPRASResultObject(statusCode, status, message, data, code, extra) { return { statusCode: statusCode || 200, status: status || "OK", message: message || "", data: data || null, code: code || "UNKNOWN_CODE", extra: extra || null, }; } responseMiddleware() { return (req, res, next) => { res.pras = { ok: (message, data, code, extra) => { res.json(this.getPRASResultObject(200, "OK", message, data, code, extra)); }, created: (message, data, code, extra) => { res.json(this.getPRASResultObject(201, "OK", message, data, code, extra)); }, badRequest: (message, data, code, extra) => { res.json(this.getPRASResultObject(400, "FAIL", message, data, code, extra)); }, unauthorized: (message, data, code, extra) => { res.json(this.getPRASResultObject(401, "FAIL", message, data, code, extra)); }, forbidden: (message, data, code, extra) => { res.json(this.getPRASResultObject(403, "FAIL", message, data, code, extra)); }, notFound: (message, data, code, extra) => { res.json(this.getPRASResultObject(404, "FAIL", message, data, code, extra)); }, serverError: (message, data, code, extra) => { res.json(this.getPRASResultObject(500, "ERROR", message, data, code, extra)); }, customMessage: (statusCode, message, data, code, extra) => { let status; if (statusCode >= 500) { status = "ERROR"; } else if (statusCode >= 400) { status = "FAIL"; } else { status = "OK"; } res.json(this.getPRASResultObject(statusCode, status, message, data, code, extra)); }, }; next(); }; } } exports.PRAS = PRAS; exports.default = new PRAS();