Skip to content

Commit

Permalink
0.13.32 added optional parameters req, res for getContacts, createCon…
Browse files Browse the repository at this point in the history
…tact, updateContact and deleteContact
  • Loading branch information
siavashcsr committed Mar 27, 2023
1 parent f263359 commit 7e85914
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sipgate/integration-bridge",
"version": "0.13.31",
"version": "0.13.32",
"description": "sipgate Integration Bridge Framework",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
21 changes: 17 additions & 4 deletions src/models/adapter.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,30 @@ import {

export interface Adapter {
getToken?: (config: Config) => Promise<{ apiKey: string }>;
getContacts?: (config: Config) => Promise<Contact[]>;
getContacts?: (
config: Config,
req?: Request,
res?: Response
) => Promise<Contact[]>;
createContact?: (
config: Config,
contact: ContactTemplate
contact: ContactTemplate,
req?: Request,
res?: Response
) => Promise<Contact>;
updateContact?: (
config: Config,
id: string,
contact: ContactUpdate
contact: ContactUpdate,
req?: Request,
res?: Response
) => Promise<Contact>;
deleteContact?: (config: Config, id: string) => Promise<void>;
deleteContact?: (
config: Config,
id: string,
req?: Request,
res?: Response
) => Promise<void>;
getCalendarEvents?: (
config: Config,
options?: CalendarFilterOptions | null
Expand Down
14 changes: 10 additions & 4 deletions src/models/controller.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export class Controller {
infoLogger(`Fetching contacts…`, providerConfig);

const fetchedContacts: Contact[] = await this.adapter.getContacts(
providerConfig
providerConfig,
req,
res
);

if (!validate(this.ajv, contactsSchema, fetchedContacts)) {
Expand Down Expand Up @@ -143,7 +145,9 @@ export class Controller {

const contact: Contact = await this.adapter.createContact(
req.providerConfig,
req.body as ContactTemplate
req.body as ContactTemplate,
req,
res
);

const valid = validate(this.ajv, contactsSchema, [contact]);
Expand Down Expand Up @@ -199,7 +203,9 @@ export class Controller {
const contact: Contact = await this.adapter.updateContact(
req.providerConfig,
req.params.id,
req.body as ContactUpdate
req.body as ContactUpdate,
req,
res
);

const valid = validate(this.ajv, contactsSchema, [contact]);
Expand Down Expand Up @@ -252,7 +258,7 @@ export class Controller {
console.log(`Deleting contact for key "${anonymizeKey(apiKey)}"`);

const contactId: string = req.params.id;
await this.adapter.deleteContact(req.providerConfig, contactId);
await this.adapter.deleteContact(req.providerConfig, contactId, req, res);

if (this.adapter.getToken && req.providerConfig) {
const { apiKey } = await this.adapter.getToken(req.providerConfig);
Expand Down

0 comments on commit 7e85914

Please sign in to comment.