UNPKG

ui5_easy_use

Version:

CLI tool for SAP ui5 and SAPUI5 projects to initialize apps, generate pages, insert form and table components, manage routing, and automate i18n bindings

40 lines (31 loc) 1.28 kB
sap.ui.define(["${ez5.appName}/${ez5.packgName}/api/OdataV4"], function (OdataV4) { "use strict"; return class UserModel { constructor(component, userData = {}) { this._componentJS = component; this.odataV4 = new OdataV4(); this.userData = userData; } hasRole(role) { return this.userData.roles?.includes(role) ?? false; } async getuserInfo(userId, appId) { let data; if (!this._componentJS.env.getFromSF) { const userInfo = Object.assign({}, this._componentJS.env.userInfo); const sStoredUserId = localStorage.getItem("UserId"); userInfo.userId = sStoredUserId || userInfo.userId; return userInfo; } const oModel = this._componentJS.getModel(); const entitySet = "sfUser"; const payload = [{ key: "userId", value: userId }, { key: "appId", value: appId }]; try { data = await this.odataV4.GETExtr(oModel, entitySet, payload); } catch (error) { console.error("Error while fetching data:", error); } return Array.isArray(data) ? data[0] : data; } }; });