From ba143936784c5d86caf159267623a3a6915dc877 Mon Sep 17 00:00:00 2001 From: Joshua Godi Date: Tue, 15 May 2018 14:02:48 -0500 Subject: [PATCH] feat(settings): Adding a settings/entitlement service (#3) * feat(settings): Adding a settings/entitlement service * feat(settings): Adding a settings/entitlement service * feat(settings): Adding a settings/entitlement service --- src/services/SettingService.ts | 33 +++++++++++++ src/services/index.ts | 1 + src/types/Responses.ts | 85 ++++++++++++++++++++++++---------- 3 files changed, 94 insertions(+), 25 deletions(-) create mode 100644 src/services/SettingService.ts diff --git a/src/services/SettingService.ts b/src/services/SettingService.ts new file mode 100644 index 0000000..c6a1407 --- /dev/null +++ b/src/services/SettingService.ts @@ -0,0 +1,33 @@ +import { AxiosInstance, AxiosResponse } from 'axios'; +import { BullhornAllSettingsAndEntitlementsResponse } from '../types'; +import { Staffing } from './Staffing'; + +/** + * A Class that defines a service to grab settings from Bullhorn + */ +export class SettingService { + http: AxiosInstance; + + constructor() { + this.http = Staffing.http(); + } + + async getSettings(settings: string[]): Promise<{ [key: string]: any }> { + const response: AxiosResponse = await this.http.get(`settings/${settings.join()}`); + return response.data; + } + + async getEntitlements(entity: string): Promise { + const response: AxiosResponse = await this.http.get(`entitlements/${entity}`); + return response.data; + } + + async getAllSettingsAndEntitlements(): Promise { + const response: AxiosResponse = await this.http.get('services/Settings/allEntitlementsAndSettings'); + const result: BullhornAllSettingsAndEntitlementsResponse = response.data; + if (result && result.dashboardEntitlements && result.entitlements) { + result.entitlements.DASHBOARD = result.dashboardEntitlements; + } + return result; + } +} diff --git a/src/services/index.ts b/src/services/index.ts index 07c6022..2f198e1 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -2,6 +2,7 @@ export * from './EntityService'; export * from './MetaService'; export * from './QueryService'; export * from './SearchService'; +export * from './SettingService'; export * from './Staffing'; export * from './StaffingAuthProvider'; export * from './Where'; diff --git a/src/types/Responses.ts b/src/types/Responses.ts index 3050dae..4b1dad6 100644 --- a/src/types/Responses.ts +++ b/src/types/Responses.ts @@ -1,44 +1,79 @@ import { Field } from './Field'; +export interface BullhornAllSettingsAndEntitlementsResponse { + settings: { [key: string]: any }; + dashboardEntitlements: string[]; + entitlements: { [key: string]: string[] }; + userData: { + id: number; + masterUserID: number; + userType: { + id: number; + name: string; + }; + firstName: string; + lastName: string; + phone: string; + mobile: string; + useDefaultMailClient: boolean; + email: string; + address: { + address1: string; + address2: string; + city: string; + state: string; + zip: string; + countryID: string; + countryName: string; + countryCode: string; + }; + departments: { + total: number; + data: { id: number; name: string }[]; + }; + srelease: boolean; + }; +} + export interface BullhornMessage { - detailMessage: string; - severity: string; - type: string; + detailMessage: string; + severity: string; + type: string; } export interface BullhornErrorMessage { - errorMessage: string; - errorMessageKey: string; - errorCode: number; + errorMessage: string; + errorMessageKey: string; + errorCode: number; } export interface BullhornMetaResponse { - entity: string; - entityMetaUrl: string; - label: string; - dateLastModified: number; - fields: Field[]; + entity: string; + entityMetaUrl: string; + label: string; + dateLastModified: number; + fields: Field[]; } export interface BullhornListResponse { - total?: number; - start: string; - count: string; - data: T[]; - messages?: BullhornMessage[]; - meta?: BullhornMetaResponse; + total?: number; + start: string; + count: string; + data: T[]; + messages?: BullhornMessage[]; + meta?: BullhornMetaResponse; } export interface BullhornEntityResponse { - data: T[]; - messages?: BullhornMessage[]; - meta?: BullhornMetaResponse; + data: T[]; + messages?: BullhornMessage[]; + meta?: BullhornMetaResponse; } export interface BullhornSavedEntityResponse { - changedEntityType: string; - changedEntityId: number; - changeType: 'INSERT' | 'UPDATE'; - messages: string[]; - data: T; + changedEntityType: string; + changedEntityId: number; + changeType: 'INSERT' | 'UPDATE'; + messages: string[]; + data: T; }