Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.13.32 added optional parameters req, res for getContacts, createCon… #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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