@63pokupki/nodejs-common
Version:
Common nodejs functionality
37 lines • 1.15 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/** Базовый контроллер */
class BaseCtrl {
/** init */
constructor(ctx) {
this.ctx = ctx;
this.responseSys = ctx.sys.responseSys;
this.errorSys = ctx.sys.errorSys;
this.userSys = ctx.sys.userSys;
this.resp = ctx.res;
this.accessSys = ctx.sys.accessSys;
}
/** init */
fClassName() {
return this.constructor.name;
}
/**
*
* @param msg - Сообщение
* @param cbAction - Анонимная функция для вызова действия
*/
async faAction(msg, cbAction) {
let out = null;
if (this.errorSys.isOk()) {
this.ctx.msg = msg;
out = await cbAction();
}
else {
this.ctx.status(401);
this.errorSys.error('init_ctrl', 'Авторизация или активация провалились');
}
this.ctx.send(JSON.stringify(this.responseSys.response(out, msg)));
}
}
exports.default = BaseCtrl;
//# sourceMappingURL=BaseCtrl.js.map