Skip to content

Commit 2f27444

Browse files
committed
✨ Add getContact route
1 parent b6d3a6c commit 2f27444

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export function start(
5353
controller.createContact(req, res, next),
5454
);
5555

56+
app.get('/contacts/:id', (req, res, next) =>
57+
controller.updateContact(req, res, next),
58+
);
59+
5660
app.put('/contacts/:id', (req, res, next) =>
5761
controller.updateContact(req, res, next),
5862
);

src/models/adapter.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ 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>;
2324
getContacts?: (config: Config) => Promise<Contact[]>;
2425
getContactsDelta?: (
2526
config: Config,

src/models/controller.model.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,52 @@ export class Controller {
447447
}
448448
}
449449

450+
public async getContact(
451+
req: BridgeRequest<unknown>,
452+
res: Response,
453+
next: NextFunction,
454+
): Promise<void> {
455+
const { providerConfig } = req;
456+
457+
if (!providerConfig) {
458+
throw new ServerError(400, 'Missing parameters');
459+
}
460+
461+
if (!this.adapter.getContact) {
462+
throw new ServerError(501, 'Getting single contact is not implemented');
463+
}
464+
465+
try {
466+
infoLogger('getContact', 'START', providerConfig.apiKey);
467+
468+
const contactId = req.params.id;
469+
const responeContact = await this.adapter.getContact(
470+
providerConfig,
471+
contactId,
472+
);
473+
474+
infoLogger('getContact', 'END', providerConfig.apiKey);
475+
res.status(200).send(responeContact);
476+
} catch (error: any) {
477+
// prevent logging of refresh errors
478+
if (
479+
error instanceof ServerError &&
480+
error.message === IntegrationErrorType.INTEGRATION_REFRESH_ERROR
481+
) {
482+
next(error);
483+
return;
484+
}
485+
486+
errorLogger(
487+
'getContact',
488+
'Could not get contact:',
489+
providerConfig.apiKey,
490+
error,
491+
);
492+
next(error);
493+
}
494+
}
495+
450496
public async createContact(
451497
req: BridgeRequest<ContactTemplate>,
452498
res: Response,

0 commit comments

Comments
 (0)