@pliancy/salesforce-cpq-sdk 3.2.0 → 3.3.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.
|
@@ -5,5 +5,6 @@ export declare class Contracts {
|
|
|
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
9
|
getDraftsByBillingPeriod(accountId: string, start: string, end: string): Promise<Contract[]>;
|
|
9
10
|
}
|
|
@@ -10,6 +10,22 @@ 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' };
|
|
15
|
+
const contracts = (await this.client.find(query));
|
|
16
|
+
if (!(contracts && contracts.length))
|
|
17
|
+
return undefined;
|
|
18
|
+
// If there's only one contract, return it
|
|
19
|
+
if (contracts.length === 1)
|
|
20
|
+
return contracts.shift();
|
|
21
|
+
contracts.sort((a, b) => {
|
|
22
|
+
const aTime = new Date(a.ActivatedDate).getTime();
|
|
23
|
+
const bTime = new Date(b.ActivatedDate).getTime();
|
|
24
|
+
return bTime - aTime;
|
|
25
|
+
});
|
|
26
|
+
// Return the first in the array
|
|
27
|
+
return contracts.shift();
|
|
28
|
+
}
|
|
13
29
|
async getDraftsByBillingPeriod(accountId, start, end) {
|
|
14
30
|
return this.client.find({
|
|
15
31
|
AccountId: accountId,
|