UNPKG

@churchapps/helpers

Version:

Library of helper functions not specific to any one ChurchApps project or framework.

61 lines 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserHelper = void 0; const ApiHelper_1 = require("./ApiHelper"); class UserHelper { static currentUserChurch; static userChurches; static user; static churchChanged = false; static person; static selectChurch = async (context, churchId, keyName) => { let userChurch = null; if (churchId) { UserHelper.userChurches.forEach(uc => { if (uc.church.id === churchId) userChurch = uc; }); } else if (keyName) UserHelper.userChurches.forEach(uc => { if (uc.church.subDomain === keyName) userChurch = uc; }); else userChurch = UserHelper.userChurches[0]; if (!userChurch) return; else { UserHelper.currentUserChurch = userChurch; UserHelper.setupApiHelper(UserHelper.currentUserChurch); // TODO - remove context code from here and perform the logic in the component itself. if (context) { if (context.userChurch !== null) UserHelper.churchChanged = true; context.setUserChurch(UserHelper.currentUserChurch); } } }; static setupApiHelper(userChurch) { ApiHelper_1.ApiHelper.setDefaultPermissions(userChurch.jwt); userChurch.apis.forEach(api => { ApiHelper_1.ApiHelper.setPermissions(api.keyName, api.jwt, api.permissions); }); } static setupApiHelperNoChurch(user) { ApiHelper_1.ApiHelper.setDefaultPermissions(user.jwt); } static checkAccess({ api, contentType, action }) { const permissions = ApiHelper_1.ApiHelper.getConfig(api).permissions; let result = false; if (permissions !== undefined) { permissions.forEach(element => { if (element.contentType === contentType && element.action === action) result = true; }); } return result; } static createAppUrl(appUrl, returnUrl) { const jwt = ApiHelper_1.ApiHelper.getConfig("MembershipApi").jwt; return `${appUrl}/login/?jwt=${jwt}&returnUrl=${returnUrl}`; } } exports.UserHelper = UserHelper; //# sourceMappingURL=UserHelper.js.map