Skip to content

Commit 8d70b4e

Browse files
committed
✨ Add type query parameter to getContactById
1 parent c25e17c commit 8d70b4e

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/models/adapter.model.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ export interface Adapter {
2020
getToken?: (config: Config) => Promise<{ apiKey: string }>;
2121
isValidToken?: (config: Config) => Promise<boolean>;
2222
getAccountId?: (config: Config) => Promise<string>;
23-
getContact?: (config: Config, id: string) => Promise<Contact>;
23+
getContact?: (
24+
config: Config,
25+
id: string,
26+
type: IntegrationEntityType,
27+
) => Promise<Contact>;
2428
getContacts?: (config: Config) => Promise<Contact[]>;
2529
getContactsDelta?: (
2630
config: Config,

src/models/controller.model.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ContactDelta,
1414
ContactTemplate,
1515
ContactUpdate,
16+
IntegrationEntityType,
1617
ServerError,
1718
} from '.';
1819
import { calendarEventsSchema, contactsSchema } from '../schemas';
@@ -464,13 +465,28 @@ export class Controller {
464465
throw new ServerError(501, 'Getting single contact is not implemented');
465466
}
466467

467-
try {
468-
infoLogger('getContact', 'START', providerConfig.apiKey);
468+
infoLogger('getContact', 'START', providerConfig.apiKey);
469+
470+
const contactType: IntegrationEntityType | undefined = Object.values(
471+
IntegrationEntityType,
472+
).find((value) => value === req.query.type?.toString());
469473

474+
if (!contactType) {
475+
throw new ServerError(400, 'Missing contact type query parameter');
476+
}
477+
478+
try {
470479
const contactId = req.params.id;
480+
infoLogger(
481+
'getContact',
482+
`Fetching contact ${contactId} of type ${contactType}`,
483+
providerConfig.apiKey,
484+
);
485+
471486
const responeContact = await this.adapter.getContact(
472487
providerConfig,
473488
contactId,
489+
contactType,
474490
);
475491

476492
infoLogger('getContact', 'END', providerConfig.apiKey);

0 commit comments

Comments
 (0)