Skip to content

Commit

Permalink
fix: 🐛 fix null params check error issue (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazyzh authored Mar 16, 2022
1 parent c899053 commit f926a9d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
47 changes: 24 additions & 23 deletions src/Session.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EventEmitter } from "events";
import { EventEmitter } from 'events';

import { SDK as RingCentralSDK } from '@ringcentral/sdk';

import { formatParty } from './formatParty';
Expand Down Expand Up @@ -323,7 +324,7 @@ export class Session extends EventEmitter {
async reload() {
const response = await this._sdk.platform().get(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}`,
null,
undefined,
this.requestOptions
);
const data = await response.json();
Expand All @@ -337,7 +338,7 @@ export class Session extends EventEmitter {
try {
await this._sdk.platform().delete(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}`,
null,
undefined,
this.requestOptions
);
} catch (e) {
Expand Down Expand Up @@ -369,8 +370,8 @@ export class Session extends EventEmitter {
const oldParty = this.party;
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${oldParty.id}/hold`,
null,
null,
undefined,
undefined,
this.requestOptions,
);
const newParty = await response.json();
Expand All @@ -383,8 +384,8 @@ export class Session extends EventEmitter {
const oldParty = this.party;
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${oldParty.id}/unhold`,
null,
null,
undefined,
undefined,
this.requestOptions,
);
const newParty = await response.json();
Expand All @@ -396,8 +397,8 @@ export class Session extends EventEmitter {
async toVoicemail() {
await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/reject`,
null,
null,
undefined,
undefined,
this.requestOptions,
);
}
Expand All @@ -406,7 +407,7 @@ export class Session extends EventEmitter {
await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/ignore`,
params,
null,
undefined,
this.requestOptions,
);
}
Expand All @@ -415,7 +416,7 @@ export class Session extends EventEmitter {
await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/answer`,
params,
null,
undefined,
this.requestOptions,
);
}
Expand All @@ -424,7 +425,7 @@ export class Session extends EventEmitter {
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/reply`,
params,
null,
undefined,
this.requestOptions,
);
const rawParty = await response.json();
Expand All @@ -437,7 +438,7 @@ export class Session extends EventEmitter {
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/forward`,
params,
null,
undefined,
this.requestOptions,
);
return response.json();
Expand All @@ -447,7 +448,7 @@ export class Session extends EventEmitter {
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/transfer`,
params,
null,
undefined,
this.requestOptions,
);
return response.json();
Expand All @@ -456,8 +457,8 @@ export class Session extends EventEmitter {
async park() {
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/park`,
null,
null,
undefined,
undefined,
this.requestOptions,
);
return response.json();
Expand All @@ -480,7 +481,7 @@ export class Session extends EventEmitter {
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/flip`,
params,
null,
undefined,
this.requestOptions,
);
return response.json();
Expand All @@ -490,7 +491,7 @@ export class Session extends EventEmitter {
const response = await this._sdk.platform().send({
method: 'PATCH',
url: `/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}`,
query: null,
query: undefined,
body: params,
userAgent: this.requestOptions.userAgent,
});
Expand All @@ -514,8 +515,8 @@ export class Session extends EventEmitter {
async createRecord() {
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/recordings`,
null,
null,
undefined,
undefined,
this.requestOptions,
);
const recording = await response.json();
Expand All @@ -530,7 +531,7 @@ export class Session extends EventEmitter {
const response = await this._sdk.platform().send({
method: 'PATCH',
url: `/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/${this.party.id}/recordings/${params.id}`,
query: null,
query: undefined,
body: {
active: params.active,
},
Expand Down Expand Up @@ -558,7 +559,7 @@ export class Session extends EventEmitter {
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/supervise`,
params,
null,
undefined,
this.requestOptions,
);
return response.json();
Expand All @@ -568,7 +569,7 @@ export class Session extends EventEmitter {
const response = await this._sdk.platform().post(
`/restapi/v1.0/account/~/telephony/sessions/${this._data.id}/parties/bring-in`,
params,
null,
undefined,
this.requestOptions,
);
return response.json();
Expand Down
23 changes: 15 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { EventEmitter } from 'events';

import { SDK as RingCentralSDK } from '@ringcentral/sdk';
import { Session, SessionData, PartyStatusCode } from './Session';

import { formatParty } from './formatParty';
import { USER_AGENT } from './userAgent';
import { ringOutInboundLegCheck } from './helper';
import {
PartyStatusCode,
Session,
SessionData,
} from './Session';
import { USER_AGENT } from './userAgent';

export interface SessionsMap {
[key: string]: any;
}
Expand Down Expand Up @@ -232,7 +239,7 @@ export class RingCentralCallControl extends EventEmitter {
private async loadCurrentExtension() {
try {
const response =
await this._sdk.platform().get('/restapi/v1.0/account/~/extension/~', null, this.requestOptions);
await this._sdk.platform().get('/restapi/v1.0/account/~/extension/~', undefined, this.requestOptions);
this._currentExtension = await response.json();
} catch (e) {
console.error('Fetch extension info error', e);
Expand All @@ -250,7 +257,7 @@ export class RingCentralCallControl extends EventEmitter {
presenceUrl = '/restapi/v1.0/account/~/presence?detailedTelephonyState=true&sipData=true';
}
try {
const response = await this._sdk.platform().get(presenceUrl, null, this.requestOptions);
const response = await this._sdk.platform().get(presenceUrl, undefined, this.requestOptions);
const data = await response.json();
if (this._accountLevel) {
const presences = data.records;
Expand Down Expand Up @@ -279,7 +286,7 @@ export class RingCentralCallControl extends EventEmitter {
const response =
await this._sdk.platform().get(
`/restapi/v1.0/account/~/telephony/sessions/${activeCall.telephonySessionId}`,
null,
undefined,
this.requestOptions,
);
const data = await response.json();
Expand Down Expand Up @@ -324,7 +331,7 @@ export class RingCentralCallControl extends EventEmitter {
const response =
await this._sdk.platform().get(
'/restapi/v1.0/account/~/extension/~/device',
null,
undefined,
this.requestOptions,
);
const data = await response.json();
Expand Down Expand Up @@ -354,7 +361,7 @@ export class RingCentralCallControl extends EventEmitter {
const response = await this._sdk.platform().post('/restapi/v1.0/account/~/telephony/call-out', {
from: { deviceId },
to,
}, null, this.requestOptions);
}, undefined, this.requestOptions);
const sessionData = (await response.json()).session;
sessionData.extensionId = this.extensionId;
sessionData.accountId = this.accountId;
Expand All @@ -379,7 +386,7 @@ export class RingCentralCallControl extends EventEmitter {
await this._sdk.platform().post(
'/restapi/v1.0/account/~/telephony/conference',
{},
null,
undefined,
this.requestOptions
);
const sessionData = (await response.json()).session;
Expand Down

0 comments on commit f926a9d

Please sign in to comment.