From c1b53312bfe58f9e576ac0aa94bccb6ea74ba30c Mon Sep 17 00:00:00 2001 From: Colin Williams <126836598+colincwilliams-kcsara@users.noreply.github.com> Date: Wed, 22 Mar 2023 10:20:32 -0700 Subject: [PATCH] Update emergency contacts Adds API support for updating emergency contacts. Also renamed HttpUtils to D4hRequest to better represent what the class is. --- lib/index.ts | 9 ++++--- lib/src/d4h.ts | 33 ++++++++++++++++++------- lib/src/{httpUtils.ts => d4hRequest.ts} | 2 +- lib/src/emergencyContacts.ts | 11 +++++++++ lib/src/member.ts | 8 +----- 5 files changed, 42 insertions(+), 21 deletions(-) rename lib/src/{httpUtils.ts => d4hRequest.ts} (95%) create mode 100644 lib/src/emergencyContacts.ts diff --git a/lib/index.ts b/lib/index.ts index 2c934f8..6f66b9d 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,7 +1,8 @@ -import D4H from './src/d4h.js' +import D4H from './src/d4h' export default D4H export * from './src/customField' -export * from './src/d4h.js' -export * from './src/group.js' -export * from './src/member.js' +export * from './src/d4h' +export * from './src/emergencyContacts' +export * from './src/group' +export * from './src/member' diff --git a/lib/src/d4h.ts b/lib/src/d4h.ts index 6f8de86..4ffc4da 100644 --- a/lib/src/d4h.ts +++ b/lib/src/d4h.ts @@ -1,7 +1,8 @@ import { CustomFieldUpdate } from './customField' +import D4HRequest from './d4hRequest' +import { EmergencyContacts } from './emergencyContacts' import { Entity, EntityType } from './entity' import type { Group } from './group' -import HttpUtils from './httpUtils' import type { Member, MemberUpdate } from './member' const D4H_FETCH_LIMIT = 250 @@ -23,10 +24,10 @@ export interface GetGroupsOptions { } export default class D4H { - private readonly _httpUtils: HttpUtils + private readonly _request: D4HRequest constructor(token: string) { - this._httpUtils = new HttpUtils(token, D4H_FETCH_LIMIT) + this._request = new D4HRequest(token, D4H_FETCH_LIMIT) } /********************************************/ @@ -44,7 +45,7 @@ export default class D4H { } } - const member = await this._httpUtils.getAsync(url) + const member = await this._request.getAsync(url) member.type = EntityType.Member return member @@ -69,7 +70,7 @@ export default class D4H { } } - const members = await this._httpUtils.getManyAsync(url) + const members = await this._request.getManyAsync(url) members.forEach(m => m.type = EntityType.Member) return members @@ -82,7 +83,21 @@ export default class D4H { } const url = new URL(`${D4H_BASE_URL}/team/members/${id}`) - return this._httpUtils.putAsync(url, updates) + return this._request.putAsync(url, updates) + } + + /********************************************/ + /*********** EMERGENCY CONTACTS *************/ + /********************************************/ + + getEmergencyContacts(memberId: number): Promise { + const url = new URL(`${D4H_BASE_URL}/team/members/${memberId}/emergency`) + return this._request.getAsync(url) + } + + updateEmergencyContacts(memberId: number, emergencyContacts: EmergencyContacts): Promise { + const url = new URL(`${D4H_BASE_URL}/team/members/${memberId}/emergency`) + return this._request.putAsync(url, emergencyContacts) } /********************************************/ @@ -91,7 +106,7 @@ export default class D4H { getGroupAsync(id: number): Promise { const url = new URL(`${D4H_BASE_URL}/team/groups/${id}`) - return this._httpUtils.getAsync(url) + return this._request.getAsync(url) } getGroupsAsync(options?: GetGroupsOptions): Promise { @@ -109,7 +124,7 @@ export default class D4H { } } - return this._httpUtils.getManyAsync(url) + return this._request.getManyAsync(url) } /********************************************/ @@ -170,6 +185,6 @@ export default class D4H { } } - return this._httpUtils.putAsync(url, { fields: updates }) + return this._request.putAsync(url, { fields: updates }) } } \ No newline at end of file diff --git a/lib/src/httpUtils.ts b/lib/src/d4hRequest.ts similarity index 95% rename from lib/src/httpUtils.ts rename to lib/src/d4hRequest.ts index 4c2a6c2..d3ac31a 100644 --- a/lib/src/httpUtils.ts +++ b/lib/src/d4hRequest.ts @@ -14,7 +14,7 @@ enum HttpMethod { Put = 'PUT', } -export default class HttpUtils { +export default class D4HRequest { private readonly _fetchLimit: number private readonly _token: string diff --git a/lib/src/emergencyContacts.ts b/lib/src/emergencyContacts.ts new file mode 100644 index 0000000..9f766b6 --- /dev/null +++ b/lib/src/emergencyContacts.ts @@ -0,0 +1,11 @@ +export interface EmergencyContact { + name: string | null + relation: string | null + phone: string | null + alt_phone: string | null +} + +export interface EmergencyContacts { + primary: EmergencyContact + secondary: EmergencyContact +} \ No newline at end of file diff --git a/lib/src/member.ts b/lib/src/member.ts index 2c1c8c4..92de8ca 100644 --- a/lib/src/member.ts +++ b/lib/src/member.ts @@ -1,12 +1,6 @@ +import { EmergencyContact } from './emergencyContacts' import { Entity } from './entity' -export interface EmergencyContact { - name: string | null - relation: string | null - phone: string | null - alt_phone: string | null -} - export interface MemberStatus { id: number type: string