@churchapps/apihelper
Version:
Library of helper functions not specific to any one ChurchApps project or framework.
58 lines • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomBaseController = void 0;
const inversify_express_utils_1 = require("inversify-express-utils");
const LoggingHelper_1 = require("../helpers/LoggingHelper");
const auth_1 = require("../auth");
class CustomBaseController extends inversify_express_utils_1.BaseHttpController {
constructor() {
super();
this.logger = LoggingHelper_1.LoggingHelper.getCurrent();
}
error(errors) {
return this.json({ errors }, 500);
}
denyAccess(errors) {
return this.json({ errors }, 401);
}
authUser() {
if (this.httpContext.user === null)
return new auth_1.AuthenticatedUser(new auth_1.Principal({}));
else
return new auth_1.AuthenticatedUser(this.httpContext.user);
}
include(req, item) {
let result = false;
if (req.query.include !== undefined) {
const value = req.query.include;
const items = value.split(",");
if (items.indexOf(item) > -1)
result = true;
}
return result;
}
async actionWrapper(_req, _res, fetchFunction) {
try {
const result = await fetchFunction(this.authUser());
await this.logger.flush();
return result;
}
catch (e) {
// Since logger.error now throws, just re-throw the error
throw e;
}
}
async actionWrapperAnon(_req, _res, fetchFunction) {
try {
const result = await fetchFunction();
await this.logger.flush();
return result;
}
catch (e) {
// Since logger.error now throws, just re-throw the error
throw e;
}
}
}
exports.CustomBaseController = CustomBaseController;
//# sourceMappingURL=CustomBaseController.js.map