UNPKG

@fdot/arculus-staff-service

Version:

Simplifies usage of the Arculus Staff Service

414 lines (413 loc) 19.7 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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 (g && (g = 0, op[0] && (_ = 0)), _) 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.getMappedManager = exports.getManager = exports.getMappedDirectReports = exports.getDirectReports = exports.clearCache = exports.getAllMappedStaffMembers = exports.getAllStaffMembers = exports.getMappedStaffByFilterCriteria = exports.getStaffByFilterCriteria = exports.getMappedActiveAndInactiveStaffByPartialName = exports.getActiveAndInactiveStaffByPartialName = exports.getMappedActiveStaffByPartialName = exports.getActiveStaffByPartialName = exports.getMappedStaffBySrsIds = exports.getStaffBySrsIds = exports.getMappedStaffBySrsId = exports.getStaffBySrsId = exports.getMappedStaffByEmailAddress = exports.getStaffByEmailAddress = exports.getMappedStaffByAzureOids = exports.getStaffByAzureOids = exports.getMappedStaffByAzureOid = exports.getStaffByAzureOid = exports.initialize = void 0; var staffApi = __importStar(require("../apis/staffApi")); var cacheService = __importStar(require("./cacheService")); var StatusFilter_1 = require("../models/enums/StatusFilter"); var initialize = function (options) { if (options === undefined || options === null) { throw new Error("Please pass a valid options object to the initialize method"); } staffApi.initialize(options); cacheService.initialize(options.cacheOptions); }; exports.initialize = initialize; var isCachingEnabled = function (cacheOptions) { return cacheOptions !== undefined ? cacheOptions.cachingEnabled : cacheService.isCachingEnabled(); }; var getStaffByAzureOid = function (oid, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var filterCriteria, matches; return __generator(this, function (_a) { switch (_a.label) { case 0: filterCriteria = { azureAdOids: [oid], }; return [4 /*yield*/, (0, exports.getStaffByFilterCriteria)(filterCriteria, cacheOptions)]; case 1: matches = _a.sent(); return [2 /*return*/, matches.length === 1 ? matches[0] : null]; } }); }); }; exports.getStaffByAzureOid = getStaffByAzureOid; var getMappedStaffByAzureOid = function (oid, mapFunction, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var staff; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, exports.getStaffByAzureOid)(oid, cacheOptions)]; case 1: staff = _a.sent(); return [2 /*return*/, staff === null ? null : mapFunction(staff)]; } }); }); }; exports.getMappedStaffByAzureOid = getMappedStaffByAzureOid; var getStaffByAzureOids = function (oids, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var filterCriteria; return __generator(this, function (_a) { filterCriteria = { azureAdOids: oids, }; return [2 /*return*/, (0, exports.getStaffByFilterCriteria)(filterCriteria, cacheOptions)]; }); }); }; exports.getStaffByAzureOids = getStaffByAzureOids; var getMappedStaffByAzureOids = function (oids, mapFunction, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var staffResults; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, exports.getStaffByAzureOids)(oids, cacheOptions)]; case 1: staffResults = _a.sent(); return [2 /*return*/, staffResults.map(mapFunction)]; } }); }); }; exports.getMappedStaffByAzureOids = getMappedStaffByAzureOids; var getStaffByEmailAddress = function (emailAddress, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var filterCriteria, matches; return __generator(this, function (_a) { switch (_a.label) { case 0: filterCriteria = { emailAddress: emailAddress, }; return [4 /*yield*/, (0, exports.getStaffByFilterCriteria)(filterCriteria, cacheOptions)]; case 1: matches = _a.sent(); return [2 /*return*/, matches.length === 1 ? matches[0] : null]; } }); }); }; exports.getStaffByEmailAddress = getStaffByEmailAddress; var getMappedStaffByEmailAddress = function (emailAddress, mapFunction, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var staff; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, exports.getStaffByEmailAddress)(emailAddress, cacheOptions)]; case 1: staff = _a.sent(); return [2 /*return*/, staff === null ? null : mapFunction(staff)]; } }); }); }; exports.getMappedStaffByEmailAddress = getMappedStaffByEmailAddress; var getStaffBySrsId = function (srsId, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var filterCriteria, matches; return __generator(this, function (_a) { switch (_a.label) { case 0: filterCriteria = { staffIds: [srsId], }; return [4 /*yield*/, (0, exports.getStaffByFilterCriteria)(filterCriteria, cacheOptions)]; case 1: matches = _a.sent(); return [2 /*return*/, matches.length === 1 ? matches[0] : null]; } }); }); }; exports.getStaffBySrsId = getStaffBySrsId; var getMappedStaffBySrsId = function (srsId, mapFunction, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var staff; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, exports.getStaffBySrsId)(srsId, cacheOptions)]; case 1: staff = _a.sent(); return [2 /*return*/, staff === null ? null : mapFunction(staff)]; } }); }); }; exports.getMappedStaffBySrsId = getMappedStaffBySrsId; var getStaffBySrsIds = function (srsIds, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var filterCriteria; return __generator(this, function (_a) { filterCriteria = { staffIds: srsIds, }; return [2 /*return*/, (0, exports.getStaffByFilterCriteria)(filterCriteria, cacheOptions)]; }); }); }; exports.getStaffBySrsIds = getStaffBySrsIds; var getMappedStaffBySrsIds = function (srsIds, mapFunction, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var staff; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, exports.getStaffBySrsIds)(srsIds, cacheOptions)]; case 1: staff = _a.sent(); return [2 /*return*/, staff.map(mapFunction)]; } }); }); }; exports.getMappedStaffBySrsIds = getMappedStaffBySrsIds; var getActiveStaffByPartialName = function (partialName, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var filterCriteria; return __generator(this, function (_a) { filterCriteria = { partialName: partialName, }; return [2 /*return*/, (0, exports.getStaffByFilterCriteria)(filterCriteria, cacheOptions)]; }); }); }; exports.getActiveStaffByPartialName = getActiveStaffByPartialName; var getMappedActiveStaffByPartialName = function (partialName, mapFunction, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var staff; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, exports.getActiveStaffByPartialName)(partialName, cacheOptions)]; case 1: staff = _a.sent(); return [2 /*return*/, staff.map(mapFunction)]; } }); }); }; exports.getMappedActiveStaffByPartialName = getMappedActiveStaffByPartialName; var getActiveAndInactiveStaffByPartialName = function (partialName, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var filterCriteria; return __generator(this, function (_a) { filterCriteria = { partialName: partialName, status: StatusFilter_1.StatusFilter.BothActiveAndInactive, }; return [2 /*return*/, (0, exports.getStaffByFilterCriteria)(filterCriteria, cacheOptions)]; }); }); }; exports.getActiveAndInactiveStaffByPartialName = getActiveAndInactiveStaffByPartialName; var getMappedActiveAndInactiveStaffByPartialName = function (partialName, mapFunction, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var staff; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, exports.getActiveAndInactiveStaffByPartialName)(partialName, cacheOptions)]; case 1: staff = _a.sent(); return [2 /*return*/, staff.map(mapFunction)]; } }); }); }; exports.getMappedActiveAndInactiveStaffByPartialName = getMappedActiveAndInactiveStaffByPartialName; var getStaffByFilterCriteria = function (filterCriteria, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var cachingEnabled; return __generator(this, function (_a) { cachingEnabled = isCachingEnabled(cacheOptions); return [2 /*return*/, new Promise(function (resolve, reject) { if (cachingEnabled) { var cachedValue = cacheService.getByFilterCriteria(filterCriteria, cacheOptions); if (cachedValue !== undefined) { resolve(cachedValue); return; } } staffApi .getStaffByFilterCriteria(filterCriteria) .then(function (staffMembers) { if (cachingEnabled && staffMembers.length > 0) { cacheService.setByFilterCriteria(filterCriteria, staffMembers, cacheOptions); } resolve(staffMembers); }) .catch(function (err) { reject(err); }); })]; }); }); }; exports.getStaffByFilterCriteria = getStaffByFilterCriteria; var getMappedStaffByFilterCriteria = function (filterCriteria, mapFunction, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var staff; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, exports.getStaffByFilterCriteria)(filterCriteria, cacheOptions)]; case 1: staff = _a.sent(); return [2 /*return*/, staff.map(mapFunction)]; } }); }); }; exports.getMappedStaffByFilterCriteria = getMappedStaffByFilterCriteria; var getAllStaffMembers = function (statusFilter, cacheOptions) { if (statusFilter === void 0) { statusFilter = StatusFilter_1.StatusFilter.ActiveOnly; } return __awaiter(void 0, void 0, void 0, function () { var cachingEnabled, cachedValue, staff; return __generator(this, function (_a) { switch (_a.label) { case 0: cachingEnabled = isCachingEnabled(cacheOptions); if (cachingEnabled) { cachedValue = cacheService.getAllStaff(statusFilter, cacheOptions); if (cachedValue) { return [2 /*return*/, cachedValue]; } } return [4 /*yield*/, staffApi.getAllStaffMembers(statusFilter)]; case 1: staff = _a.sent(); if (cachingEnabled) { cacheService.setAllStaff(statusFilter, staff, cacheOptions); } return [2 /*return*/, staff]; } }); }); }; exports.getAllStaffMembers = getAllStaffMembers; var getAllMappedStaffMembers = function (statusFilter, mapFunction, cacheOptions) { if (statusFilter === void 0) { statusFilter = StatusFilter_1.StatusFilter.ActiveOnly; } return __awaiter(void 0, void 0, void 0, function () { var staff; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, exports.getAllStaffMembers)(statusFilter, cacheOptions)]; case 1: staff = _a.sent(); return [2 /*return*/, staff.map(mapFunction)]; } }); }); }; exports.getAllMappedStaffMembers = getAllMappedStaffMembers; var clearCache = function () { cacheService.clearCache(); }; exports.clearCache = clearCache; var getDirectReports = function (srsId, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var cachingEnabled; return __generator(this, function (_a) { cachingEnabled = isCachingEnabled(cacheOptions); return [2 /*return*/, new Promise(function (resolve, reject) { if (cachingEnabled) { var cachedValue = cacheService.getDirectReports(srsId, cacheOptions); if (cachedValue !== undefined) { resolve(cachedValue); return; } } staffApi .getDirectReports(srsId) .then(function (staffMembers) { if (cachingEnabled && staffMembers.length > 0) { cacheService.setDirectReports(srsId, staffMembers, cacheOptions); } resolve(staffMembers); }) .catch(function (err) { reject(err); }); })]; }); }); }; exports.getDirectReports = getDirectReports; var getMappedDirectReports = function (srsId, mapFunction, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var staff; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, exports.getDirectReports)(srsId, cacheOptions)]; case 1: staff = _a.sent(); return [2 /*return*/, staff.map(mapFunction)]; } }); }); }; exports.getMappedDirectReports = getMappedDirectReports; var getManager = function (srsId, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var cachingEnabled; return __generator(this, function (_a) { cachingEnabled = isCachingEnabled(cacheOptions); return [2 /*return*/, new Promise(function (resolve, reject) { if (cachingEnabled) { var cachedValue = cacheService.getManager(srsId, cacheOptions); if (cachedValue !== undefined) { resolve(cachedValue); return; } } staffApi .getManager(srsId) .then(function (staffMember) { if (cachingEnabled && staffMember) { cacheService.setManager(srsId, staffMember, cacheOptions); } resolve(staffMember); }) .catch(function (err) { reject(err); }); })]; }); }); }; exports.getManager = getManager; var getMappedManager = function (srsId, mapFunction, cacheOptions) { return __awaiter(void 0, void 0, void 0, function () { var staff; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, exports.getManager)(srsId, cacheOptions)]; case 1: staff = _a.sent(); return [2 /*return*/, mapFunction(staff)]; } }); }); }; exports.getMappedManager = getMappedManager;