UNPKG

wfm-mobile-core

Version:

WFM Mobile Core

361 lines (360 loc) 19.7 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserApi = void 0; var mobx_1 = require("mobx"); var __1 = require(".."); var helpers_1 = require("../helpers"); var constants_1 = require("../constants"); var EFetchingStatus_1 = require("../enums/EFetchingStatus"); var http_1 = require("../http"); var Permissions_1 = require("./Permissions"); var Shifts_1 = require("./Shifts"); var utils_1 = require("../utils"); var UserApi = /** @class */ (function () { function UserApi() { } UserApi.setFetchingUserStatus = function (newStatus) { UserApi.fetchingStatusUser = newStatus; }; UserApi.rejected = function (error) { this.error = error; UserApi.setFetchingUserStatus(EFetchingStatus_1.EFetchingStatus.ERROR); return Promise.reject(error); }; UserApi.resolved = function (response) { UserApi.setFetchingUserStatus(EFetchingStatus_1.EFetchingStatus.DONE); return Promise.resolve(response); }; UserApi.getUser = function (_a) { var _b; var startDate = _a.startDate, endDate = _a.endDate; return __awaiter(this, void 0, void 0, function () { var response, e_1; return __generator(this, function (_c) { switch (_c.label) { case 0: this.setFetchingUserStatus(EFetchingStatus_1.EFetchingStatus.IN_PROGRESS); _c.label = 1; case 1: _c.trys.push([1, 3, , 4]); return [4 /*yield*/, http_1.httpClient.get((_b = http_1.httpClient === null || http_1.httpClient === void 0 ? void 0 : http_1.httpClient.links[constants_1.ResourceNames.USER_EMPLOYEE]) === null || _b === void 0 ? void 0 : _b.href, constants_1.headersHAL)]; case 2: response = (_c.sent()); UserApi.userEmployee = response; UserApi.userLinks = response === null || response === void 0 ? void 0 : response._links; UserApi.isComplete = true; this.getUserEmployeePositions(); this.getEventTypes(); this.getEmployeeHours(); this.getUserTags(); this.getAvailableTags(); this.getUserBio(); Shifts_1.ShiftsApi.getShifts({ startDate: startDate, endDate: endDate }); Permissions_1.PermissionsApi.getUserRoles(); return [2 /*return*/, this.resolved(response)]; case 3: e_1 = _c.sent(); return [2 /*return*/, this.rejected(e_1)]; case 4: return [2 /*return*/]; } }); }); }; UserApi.getEventTypes = function () { var _a; return __awaiter(this, void 0, void 0, function () { var url, response, e_2; return __generator(this, function (_b) { switch (_b.label) { case 0: _b.trys.push([0, 2, , 3]); url = utils_1.parseLinksTemplate(http_1.httpClient.links[constants_1.ResourceNames.SCHEDULE_REQUEST_ALIASES].href); return [4 /*yield*/, http_1.httpClient.get(url, constants_1.headersJSON)]; case 1: response = (_b.sent()); UserApi.eventTypes = (_a = response === null || response === void 0 ? void 0 : response.filter(function (item) { return item.value !== 'NON_APPEARANCE'; })) !== null && _a !== void 0 ? _a : []; return [2 /*return*/, Promise.resolve(response)]; case 2: e_2 = _b.sent(); return [2 /*return*/, this.rejected(e_2)]; case 3: return [2 /*return*/]; } }); }); }; UserApi.getEmployeeHours = function () { var _a, _b, _c; return __awaiter(this, void 0, void 0, function () { var response, e_3; return __generator(this, function (_d) { switch (_d.label) { case 0: _d.trys.push([0, 2, , 3]); return [4 /*yield*/, http_1.httpClient.get((_c = (_b = (_a = http_1.httpClient.links) === null || _a === void 0 ? void 0 : _a[constants_1.ResourceNames.EMPLOYEE_HOURS]) === null || _b === void 0 ? void 0 : _b.href) !== null && _c !== void 0 ? _c : '', constants_1.headersHAL)]; case 1: response = (_d.sent()); this.employeeHours = response; return [2 /*return*/, Promise.resolve(response)]; case 2: e_3 = _d.sent(); return [2 /*return*/, Promise.reject(e_3)]; case 3: return [2 /*return*/]; } }); }); }; UserApi.getUserEmployeePositions = function () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; return __awaiter(this, void 0, void 0, function () { var response; return __generator(this, function (_m) { switch (_m.label) { case 0: return [4 /*yield*/, this.loadUserData()]; case 1: response = (_m.sent()); UserApi.employeePositions = (_a = response === null || response === void 0 ? void 0 : response._embedded) === null || _a === void 0 ? void 0 : _a.employeePositions; UserApi.position = (_e = (_d = (_c = (_b = response === null || response === void 0 ? void 0 : response._embedded.employeePositions[0]) === null || _b === void 0 ? void 0 : _b._embedded) === null || _c === void 0 ? void 0 : _c.position) === null || _d === void 0 ? void 0 : _d._links) === null || _e === void 0 ? void 0 : _e.self.href; UserApi.positionCategoryId = (_h = (_g = (_f = response === null || response === void 0 ? void 0 : response._embedded.employeePositions[0]) === null || _f === void 0 ? void 0 : _f._embedded) === null || _g === void 0 ? void 0 : _g.position) === null || _h === void 0 ? void 0 : _h.positionCategoryId; UserApi.orgUnitId = (_l = (_k = (_j = response === null || response === void 0 ? void 0 : response._embedded.employeePositions[0]) === null || _j === void 0 ? void 0 : _j._embedded) === null || _k === void 0 ? void 0 : _k.position) === null || _l === void 0 ? void 0 : _l.organizationUnitId; return [2 /*return*/, Promise.resolve(response)]; } }); }); }; UserApi.getUserTags = function () { var _a, _b; return __awaiter(this, void 0, void 0, function () { var response, e_4; return __generator(this, function (_c) { switch (_c.label) { case 0: _c.trys.push([0, 2, , 3]); return [4 /*yield*/, http_1.httpClient.get((_b = (_a = UserApi.userLinks) === null || _a === void 0 ? void 0 : _a.tags) === null || _b === void 0 ? void 0 : _b.href, constants_1.headersHAL)]; case 1: response = (_c.sent()); UserApi.userTags = response === null || response === void 0 ? void 0 : response.tags; UserApi.userTagsLinks = response === null || response === void 0 ? void 0 : response._links; return [2 /*return*/, Promise.resolve(response)]; case 2: e_4 = _c.sent(); return [2 /*return*/, Promise.reject(e_4)]; case 3: return [2 /*return*/]; } }); }); }; UserApi.getAvailableTags = function () { var _a, _b, _c; return __awaiter(this, void 0, void 0, function () { var url, response, tags, e_5; return __generator(this, function (_d) { switch (_d.label) { case 0: _d.trys.push([0, 2, , 3]); url = http_1.httpClient.entryPoint + "/" + [constants_1.ResourceNames.TAGS] + "?" + [constants_1.ResourceNames.ENTITY] + "=" + [ constants_1.ResourceNames.ORGANIZATION_UNIT, ] + "&size=" + 1e5; return [4 /*yield*/, http_1.httpClient.get(url, constants_1.headersHAL)]; case 1: response = (_d.sent()); tags = (_c = (_b = (_a = response === null || response === void 0 ? void 0 : response._embedded) === null || _a === void 0 ? void 0 : _a.tagResourceList) === null || _b === void 0 ? void 0 : _b.map(function (t) { return t.name; })) !== null && _c !== void 0 ? _c : []; UserApi.availableTags = tags; return [2 /*return*/, Promise.resolve(response)]; case 2: e_5 = _d.sent(); return [2 /*return*/, Promise.reject(e_5)]; case 3: return [2 /*return*/]; } }); }); }; UserApi.getUserBio = function () { var _a, _b, _c, _d, _e, _f, _g, _h, _j; return __awaiter(this, void 0, void 0, function () { var today, orgUnitResourceResponse, orgUnitInfo, bioLink, bioRecordsResponse, e_6; return __generator(this, function (_k) { switch (_k.label) { case 0: today = helpers_1.dateISOFormat(new Date()); _k.label = 1; case 1: _k.trys.push([1, 6, , 7]); return [4 /*yield*/, http_1.httpClient.get((_b = (_a = http_1.httpClient === null || http_1.httpClient === void 0 ? void 0 : http_1.httpClient.links) === null || _a === void 0 ? void 0 : _a.orgUnits) === null || _b === void 0 ? void 0 : _b.href, constants_1.headersHAL)]; case 2: orgUnitResourceResponse = (_k.sent()); return [4 /*yield*/, http_1.httpClient.get((_f = (_e = (_d = (_c = orgUnitResourceResponse === null || orgUnitResourceResponse === void 0 ? void 0 : orgUnitResourceResponse._embedded) === null || _c === void 0 ? void 0 : _c.orgUnits[0]) === null || _d === void 0 ? void 0 : _d._links) === null || _e === void 0 ? void 0 : _e.self) === null || _f === void 0 ? void 0 : _f.href, constants_1.headersHAL)]; case 3: orgUnitInfo = (_k.sent()); bioLink = (_h = (_g = orgUnitInfo === null || orgUnitInfo === void 0 ? void 0 : orgUnitInfo._links) === null || _g === void 0 ? void 0 : _g.records) === null || _h === void 0 ? void 0 : _h.href; if (!bioLink) return [3 /*break*/, 5]; return [4 /*yield*/, http_1.httpClient.get(__1.parseLinks(bioLink) + "?from=" + today + "&to=" + today, constants_1.headersHAL)]; case 4: bioRecordsResponse = (_k.sent()); UserApi.bioRecord = (_j = bioRecordsResponse === null || bioRecordsResponse === void 0 ? void 0 : bioRecordsResponse._embedded) === null || _j === void 0 ? void 0 : _j.bioRecordResourceList.find(function (record) { var _a, _b, _c, _d, _e; return ((_b = (_a = record === null || record === void 0 ? void 0 : record._links) === null || _a === void 0 ? void 0 : _a.bioRecEmployee) === null || _b === void 0 ? void 0 : _b.href) === ((_e = (_d = (_c = UserApi.userEmployee) === null || _c === void 0 ? void 0 : _c._links) === null || _d === void 0 ? void 0 : _d.self) === null || _e === void 0 ? void 0 : _e.href); }); return [2 /*return*/, Promise.resolve(bioRecordsResponse)]; case 5: return [2 /*return*/, Promise.resolve(orgUnitInfo)]; case 6: e_6 = _k.sent(); return [2 /*return*/, Promise.reject(e_6)]; case 7: return [2 /*return*/]; } }); }); }; UserApi.putUserTags = function (link, tags) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.shiftAction('put', link, tags)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; UserApi.shiftAction = function (action, link, properties) { return __awaiter(this, void 0, void 0, function () { var response, e_7; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); return [4 /*yield*/, http_1.httpClient[action](link, constants_1.headersHAL, properties)]; case 1: response = _a.sent(); return [2 /*return*/, Promise.resolve(response)]; case 2: e_7 = _a.sent(); return [2 /*return*/, Promise.reject(e_7)]; case 3: return [2 /*return*/]; } }); }); }; UserApi.putUserEmployee = function (link, userEmployee) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.shiftAction('put', link, userEmployee)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; UserApi.loadUserData = function () { return __awaiter(this, void 0, void 0, function () { var response, e_8; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); return [4 /*yield*/, http_1.httpClient.get(http_1.httpClient.links[constants_1.ResourceNames.USER_EMPLOYEE_POSITIONS].href, constants_1.headersHAL)]; case 1: response = (_a.sent()); return [2 /*return*/, Promise.resolve(response)]; case 2: e_8 = _a.sent(); return [2 /*return*/, Promise.reject(e_8)]; case 3: return [2 /*return*/]; } }); }); }; UserApi.error = {}; UserApi.totalArrayByRender = []; UserApi.eventTypes = []; UserApi.isComplete = false; UserApi.availableTags = []; UserApi.fetchingStatusUser = EFetchingStatus_1.EFetchingStatus.NONE; __decorate([ mobx_1.observable ], UserApi, "userEmployee", void 0); __decorate([ mobx_1.observable ], UserApi, "error", void 0); __decorate([ mobx_1.observable ], UserApi, "totalArrayByRender", void 0); __decorate([ mobx_1.observable ], UserApi, "userLinks", void 0); __decorate([ mobx_1.observable ], UserApi, "position", void 0); __decorate([ mobx_1.observable ], UserApi, "positionCategoryId", void 0); __decorate([ mobx_1.observable ], UserApi, "employeePositions", void 0); __decorate([ mobx_1.observable ], UserApi, "orgUnitId", void 0); __decorate([ mobx_1.observable ], UserApi, "eventTypes", void 0); __decorate([ mobx_1.observable ], UserApi, "employeeHours", void 0); __decorate([ mobx_1.observable ], UserApi, "isComplete", void 0); __decorate([ mobx_1.observable ], UserApi, "userTags", void 0); __decorate([ mobx_1.observable ], UserApi, "userTagsLinks", void 0); __decorate([ mobx_1.observable ], UserApi, "availableTags", void 0); __decorate([ mobx_1.observable ], UserApi, "bioRecord", void 0); __decorate([ mobx_1.observable ], UserApi, "fetchingStatusUser", void 0); return UserApi; }()); exports.UserApi = UserApi;