@pliancy/salesforce-cpq-sdk 3.8.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address } from 'jsforce';
|
|
1
|
+
import { Address, QueryCondition, Schema } from 'jsforce';
|
|
2
2
|
export interface Contract {
|
|
3
3
|
[index: string]: any;
|
|
4
4
|
Id: string;
|
|
@@ -85,3 +85,4 @@ export interface Contract {
|
|
|
85
85
|
SBQQ__OpportunityPricebookId__c: string;
|
|
86
86
|
}
|
|
87
87
|
export type ContractStatus = 'Draft' | 'Activated' | 'In Approval Process';
|
|
88
|
+
export type ContractQuery = QueryCondition<Schema, 'SBQQ__Contract__c'>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Connection } from 'jsforce';
|
|
2
|
-
import { Contract } from './contract.types';
|
|
2
|
+
import { Contract, ContractQuery } from './contract.types';
|
|
3
3
|
export declare class Contracts {
|
|
4
4
|
private readonly connection;
|
|
5
5
|
private readonly client;
|
|
6
6
|
constructor(connection: Connection);
|
|
7
7
|
getById(id: string): Promise<Contract | null>;
|
|
8
|
-
getLatestActivatedByAccountId(id: string): Promise<Contract | undefined>;
|
|
8
|
+
getLatestActivatedByAccountId(id: string, options?: ContractQuery): Promise<Contract | undefined>;
|
|
9
9
|
getDraftsByBillingPeriod(accountId: string, start: string, end: string): Promise<Contract[]>;
|
|
10
|
+
private buildQuery;
|
|
10
11
|
}
|
|
@@ -10,8 +10,8 @@ class Contracts {
|
|
|
10
10
|
async getById(id) {
|
|
11
11
|
return this.client.findOne({ Id: id });
|
|
12
12
|
}
|
|
13
|
-
async getLatestActivatedByAccountId(id) {
|
|
14
|
-
const query = { AccountId: id, Status: 'Activated' };
|
|
13
|
+
async getLatestActivatedByAccountId(id, options) {
|
|
14
|
+
const query = this.buildQuery({ AccountId: id, Status: 'Activated' }, options);
|
|
15
15
|
const contracts = (await this.client.find(query));
|
|
16
16
|
if (!(contracts && contracts.length))
|
|
17
17
|
return undefined;
|
|
@@ -34,5 +34,11 @@ class Contracts {
|
|
|
34
34
|
EndDate: { $lte: new jsforce_1.SfDate(end) },
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
+
buildQuery(base, options) {
|
|
38
|
+
const query = { ...base };
|
|
39
|
+
if (options)
|
|
40
|
+
Object.assign(query, options);
|
|
41
|
+
return query;
|
|
42
|
+
}
|
|
37
43
|
}
|
|
38
44
|
exports.Contracts = Contracts;
|
|
@@ -76,14 +76,21 @@ class Quotes {
|
|
|
76
76
|
return this.client.update(query);
|
|
77
77
|
}
|
|
78
78
|
async submitAndApprove(quoteId, comments = '') {
|
|
79
|
+
var _a;
|
|
79
80
|
try {
|
|
80
81
|
const { ApprovalProcess } = require('jsforce/lib/process');
|
|
81
82
|
const approvalProcess = new ApprovalProcess(this.connection);
|
|
82
83
|
const sResult = (await approvalProcess.submit(quoteId, comments, {
|
|
83
84
|
skipEntryCriteria: true,
|
|
84
85
|
}));
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
// JsForce types say the field is 'newWorkItemIds', but the actual result is 'newWorkitemIds'.
|
|
87
|
+
// Look for the actual API return first, then what the types say it should be, default
|
|
88
|
+
// to empty array.
|
|
89
|
+
const workItemIds = sResult.hasOwnProperty('newWorkitemIds')
|
|
90
|
+
? sResult['newWorkitemIds']
|
|
91
|
+
: (_a = sResult === null || sResult === void 0 ? void 0 : sResult.newWorkItemIds) !== null && _a !== void 0 ? _a : [];
|
|
92
|
+
if (workItemIds && workItemIds.length) {
|
|
93
|
+
const id = workItemIds[0];
|
|
87
94
|
if (!id)
|
|
88
95
|
return { success: false, errors: ['No workItemId returned'] };
|
|
89
96
|
await approvalProcess.approve(id);
|