@adobe/spacecat-shared-data-access 1.53.1 → 1.55.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.
- package/CHANGELOG.md +14 -0
- package/package.json +4 -1
- package/src/index.d.ts +6 -0
- package/src/index.js +5 -0
- package/src/models/configuration.js +4 -0
- package/src/service/index.js +52 -0
- package/src/v2/errors/index.d.ts +13 -0
- package/src/v2/errors/index.js +15 -0
- package/src/v2/errors/validation.error.js +13 -0
- package/src/v2/index.d.ts +15 -0
- package/src/v2/index.js +15 -0
- package/src/v2/models/base.collection.js +118 -0
- package/src/v2/models/base.model.js +127 -0
- package/src/v2/models/index.d.ts +100 -0
- package/src/v2/models/index.js +27 -0
- package/src/v2/models/model.factory.js +74 -0
- package/src/v2/models/opportunity.collection.js +78 -0
- package/src/v2/models/opportunity.model.js +238 -0
- package/src/v2/models/suggestion.collection.js +80 -0
- package/src/v2/models/suggestion.model.js +138 -0
- package/src/v2/readme.md +260 -0
- package/src/v2/schema/opportunity.schema.js +145 -0
- package/src/v2/schema/suggestion.schema.js +122 -0
- package/src/v2/util/guards.d.ts +62 -0
- package/src/v2/util/guards.js +165 -0
- package/src/v2/util/index.d.ts +13 -0
- package/src/v2/util/index.js +22 -0
- package/src/v2/util/patcher.js +183 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import OpportunityCollection from './opportunity.collection.js';
|
|
14
|
+
import SuggestionCollection from './suggestion.collection.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* ModelFactory - A factory class responsible for creating and managing collections
|
|
18
|
+
* of different models. This class serves as a centralized point for accessing and
|
|
19
|
+
* instantiating model collections.
|
|
20
|
+
*
|
|
21
|
+
* @class ModelFactory
|
|
22
|
+
*/
|
|
23
|
+
class ModelFactory {
|
|
24
|
+
/**
|
|
25
|
+
* Constructs an instance of ModelFactory.
|
|
26
|
+
* @constructor
|
|
27
|
+
* @param {Object} service - The ElectroDB service instance used to manage entities.
|
|
28
|
+
* @param {Object} logger - A logger for capturing and logging information.
|
|
29
|
+
*/
|
|
30
|
+
constructor(service, logger) {
|
|
31
|
+
this.service = service;
|
|
32
|
+
this.logger = logger;
|
|
33
|
+
this.models = new Map();
|
|
34
|
+
|
|
35
|
+
this.initialize();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Initializes the collections managed by the ModelFactory.
|
|
40
|
+
* This method creates instances of each collection and stores them in an internal map.
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
initialize() {
|
|
44
|
+
const opportunityCollection = new OpportunityCollection(
|
|
45
|
+
this.service,
|
|
46
|
+
this,
|
|
47
|
+
this.logger,
|
|
48
|
+
);
|
|
49
|
+
const suggestionCollection = new SuggestionCollection(
|
|
50
|
+
this.service,
|
|
51
|
+
this,
|
|
52
|
+
this.logger,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
this.models.set(OpportunityCollection.name, opportunityCollection);
|
|
56
|
+
this.models.set(SuggestionCollection.name, suggestionCollection);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Gets a collection instance by its name.
|
|
61
|
+
* @param {string} collectionName - The name of the collection to retrieve.
|
|
62
|
+
* @returns {Object} - The requested collection instance.
|
|
63
|
+
* @throws {Error} - Throws an error if the collection with the specified name is not found.
|
|
64
|
+
*/
|
|
65
|
+
getCollection(collectionName) {
|
|
66
|
+
const collection = this.models.get(collectionName);
|
|
67
|
+
if (!collection) {
|
|
68
|
+
throw new Error(`Collection ${collectionName} not found`);
|
|
69
|
+
}
|
|
70
|
+
return collection;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default ModelFactory;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { hasText } from '@adobe/spacecat-shared-utils';
|
|
14
|
+
|
|
15
|
+
import BaseCollection from './base.collection.js';
|
|
16
|
+
import Opportunity from './opportunity.model.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* OpportunityCollection - A collection class responsible for managing Opportunity entities.
|
|
20
|
+
* Extends the BaseCollection to provide specific methods for interacting with Opportunity records.
|
|
21
|
+
*
|
|
22
|
+
* @class OpportunityCollection
|
|
23
|
+
* @extends BaseCollection
|
|
24
|
+
*/
|
|
25
|
+
class OpportunityCollection extends BaseCollection {
|
|
26
|
+
/**
|
|
27
|
+
* Constructs an instance of OpportunityCollection. Tells the base class which model to use.
|
|
28
|
+
* @constructor
|
|
29
|
+
* @param {Object} service - The ElectroDB service instance used to manage Opportunity entities.
|
|
30
|
+
* @param {Object} modelFactory - A factory for creating model instances.
|
|
31
|
+
* @param {Object} log - A logger for capturing logging information.
|
|
32
|
+
*/
|
|
33
|
+
constructor(service, modelFactory, log) {
|
|
34
|
+
super(service, modelFactory, Opportunity, log);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves all Opportunity entities by their associated site ID.
|
|
39
|
+
* @async
|
|
40
|
+
* @param {string} siteId - The unique identifier of the site.
|
|
41
|
+
* @returns {Promise<Array<Opportunity>>} - A promise that resolves to an array of
|
|
42
|
+
* Opportunity instances related to the given site ID.
|
|
43
|
+
* @throws {Error} - Throws an error if the siteId is not provided or if the query fails.
|
|
44
|
+
*/
|
|
45
|
+
async allBySiteId(siteId) {
|
|
46
|
+
if (!hasText(siteId)) {
|
|
47
|
+
throw new Error('SiteId is required');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const records = await this.entity.query.bySiteId({ siteId }).go();
|
|
51
|
+
|
|
52
|
+
return this._createInstances(records);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves all Opportunity entities by their associated site ID and status.
|
|
57
|
+
* @param {string} siteId - The unique identifier of the site.
|
|
58
|
+
* @param {string} status - The status of the Opportunity entities to retrieve.
|
|
59
|
+
* @return {Promise<Array<BaseModel>>} - A promise that resolves to an array of
|
|
60
|
+
* Opportunity instances.
|
|
61
|
+
* @throws {Error} - Throws an error if the siteId or status is not provided or if the
|
|
62
|
+
* query fails.
|
|
63
|
+
*/
|
|
64
|
+
async allBySiteIdAndStatus(siteId, status) {
|
|
65
|
+
if (!hasText(siteId)) {
|
|
66
|
+
throw new Error('SiteId is required');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!hasText(status)) {
|
|
70
|
+
throw new Error('Status is required');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const records = await this.entity.query.bySiteIdAndStatus({ siteId, status }).go();
|
|
74
|
+
return this._createInstances(records);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default OpportunityCollection;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import BaseModel from './base.model.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Opportunity - A class representing an Opportunity entity.
|
|
17
|
+
* Provides methods to access and manipulate Opportunity-specific data,
|
|
18
|
+
* such as related suggestions, audit IDs, site IDs, etc.
|
|
19
|
+
*
|
|
20
|
+
* @class Opportunity
|
|
21
|
+
* @extends BaseModel
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
class Opportunity extends BaseModel {
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves all Suggestion entities associated to this Opportunity.
|
|
27
|
+
* @async
|
|
28
|
+
* @returns {Promise<Array<Suggestion>>} - A promise that resolves to an array of Suggestion
|
|
29
|
+
* instances associated with this Opportunity.
|
|
30
|
+
*/
|
|
31
|
+
async getSuggestions() {
|
|
32
|
+
return this._getAssociation(
|
|
33
|
+
'SuggestionCollection',
|
|
34
|
+
'allByOpportunityId',
|
|
35
|
+
this.getId(),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gets the ID of the site associated with this Opportunity.
|
|
41
|
+
* @returns {string} - The unique identifier of the site.
|
|
42
|
+
*/
|
|
43
|
+
getSiteId() {
|
|
44
|
+
return this.record.siteId;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Sets the site ID for this Opportunity (associates it with a site).
|
|
49
|
+
* @param {string} siteId - The unique identifier of the site.
|
|
50
|
+
* @returns {Opportunity} - The current instance of Opportunity for chaining.
|
|
51
|
+
* @throws {Error} - Throws an error if the siteId is not a valid UUID.
|
|
52
|
+
*/
|
|
53
|
+
setSiteId(siteId) {
|
|
54
|
+
this.patcher.patchValue('siteId', siteId, true);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Gets the ID of the audit associated with this Opportunity.
|
|
60
|
+
* @returns {string} - The unique identifier of the audit.
|
|
61
|
+
*/
|
|
62
|
+
getAuditId() {
|
|
63
|
+
return this.record.auditId;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Sets the audit ID for this Opportunity (associates it with an audit).
|
|
68
|
+
* @param {string} auditId - The unique identifier of the audit.
|
|
69
|
+
* @returns {Opportunity} - The current instance of Opportunity for chaining.
|
|
70
|
+
* @throws {Error} - Throws an error if the auditId is not a valid UUID.
|
|
71
|
+
*/
|
|
72
|
+
setAuditId(auditId) {
|
|
73
|
+
this.patcher.patchValue('auditId', auditId, true);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Gets the runbook URL or reference for this Opportunity.
|
|
79
|
+
* @returns {string} - The runbook reference for this Opportunity.
|
|
80
|
+
*/
|
|
81
|
+
getRunbook() {
|
|
82
|
+
return this.record.runbook;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Sets the runbook URL or reference for this Opportunity.
|
|
87
|
+
* @param {string} runbook - The runbook reference or URL.
|
|
88
|
+
* @returns {Opportunity} - The current instance of Opportunity for chaining.
|
|
89
|
+
* @throws {Error} - Throws an error if the runbook is not a string or empty.
|
|
90
|
+
*/
|
|
91
|
+
setRunbook(runbook) {
|
|
92
|
+
this.patcher.patchValue('runbook', runbook);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Gets the guidance information for this Opportunity.
|
|
98
|
+
* @returns {Object} - The guidance object for this Opportunity.
|
|
99
|
+
*/
|
|
100
|
+
getGuidance() {
|
|
101
|
+
return this.record.guidance;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Sets the guidance information for this Opportunity.
|
|
106
|
+
* @param {Object} guidance - The guidance object.
|
|
107
|
+
* @returns {Opportunity} - The current instance of Opportunity for chaining.
|
|
108
|
+
* @throws {Error} - Throws an error if the guidance is not an object or empty.
|
|
109
|
+
*/
|
|
110
|
+
setGuidance(guidance) {
|
|
111
|
+
this.patcher.patchValue('guidance', guidance);
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Gets the title of this Opportunity.
|
|
117
|
+
* @returns {string} - The title of the Opportunity.
|
|
118
|
+
*/
|
|
119
|
+
getTitle() {
|
|
120
|
+
return this.record.title;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Sets the title of this Opportunity.
|
|
125
|
+
* @param {string} title - The title of the Opportunity.
|
|
126
|
+
* @returns {Opportunity} - The current instance of Opportunity for chaining.
|
|
127
|
+
* @throws {Error} - Throws an error if the title is not a string or empty.
|
|
128
|
+
*/
|
|
129
|
+
setTitle(title) {
|
|
130
|
+
this.patcher.patchValue('title', title);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Gets the description of this Opportunity.
|
|
136
|
+
* @returns {string} - The description of the Opportunity.
|
|
137
|
+
*/
|
|
138
|
+
getDescription() {
|
|
139
|
+
return this.record.description;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Sets the description of this Opportunity.
|
|
144
|
+
* @param {string} description - The description of the Opportunity.
|
|
145
|
+
* @returns {Opportunity} - The current instance of Opportunity for chaining.
|
|
146
|
+
* @throws {Error} - Throws an error if the description is not a string or empty.
|
|
147
|
+
*/
|
|
148
|
+
setDescription(description) {
|
|
149
|
+
this.patcher.patchValue('description', description);
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Gets the type of this Opportunity.
|
|
155
|
+
* @returns {string} - The type of the Opportunity.
|
|
156
|
+
*/
|
|
157
|
+
getType() {
|
|
158
|
+
return this.record.type;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Gets the status of this Opportunity.
|
|
163
|
+
* @returns {string} - The status of the Opportunity.
|
|
164
|
+
*/
|
|
165
|
+
getStatus() {
|
|
166
|
+
return this.record.status;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Sets the status of this Opportunity. Check the schema for valid status values.
|
|
171
|
+
* @param {string} status - The status of the Opportunity.
|
|
172
|
+
* @returns {Opportunity} - The current instance of Opportunity for chaining.
|
|
173
|
+
* @throws {Error} - Throws an error if the status is not a valid value.
|
|
174
|
+
*/
|
|
175
|
+
setStatus(status) {
|
|
176
|
+
this.patcher.patchValue('status', status);
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Gets the origin of this Opportunity.
|
|
182
|
+
* @returns {string} - The origin of the Opportunity (e.g., ESS_OPS, AI, AUTOMATION).
|
|
183
|
+
*/
|
|
184
|
+
getOrigin() {
|
|
185
|
+
return this.record.origin;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Sets the origin of this Opportunity. Check the schema for valid origin values.
|
|
190
|
+
* @param {string} origin - The origin of the Opportunity.
|
|
191
|
+
* @returns {Opportunity} - The current instance of Opportunity for chaining.
|
|
192
|
+
* @throws {Error} - Throws an error if the origin is not a valid value.
|
|
193
|
+
*/
|
|
194
|
+
setOrigin(origin) {
|
|
195
|
+
this.patcher.patchValue('origin', origin);
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Gets the tags associated with this Opportunity.
|
|
201
|
+
* @returns {Array<string>} - An array of tags associated with the Opportunity.
|
|
202
|
+
*/
|
|
203
|
+
getTags() {
|
|
204
|
+
return this.record.tags;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Sets the tags for this Opportunity. Duplicate tags are made unique.
|
|
209
|
+
* @param {Array<string>} tags - An array of tags to associate with the Opportunity.
|
|
210
|
+
* @returns {Opportunity} - The current instance of Opportunity for chaining.
|
|
211
|
+
* @throws {Error} - Throws an error if the tags are not an array.
|
|
212
|
+
*/
|
|
213
|
+
setTags(tags) {
|
|
214
|
+
this.patcher.patchValue('tags', tags);
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Gets additional data associated with this Opportunity.
|
|
220
|
+
* @returns {Object} - The additional data for the Opportunity.
|
|
221
|
+
*/
|
|
222
|
+
getData() {
|
|
223
|
+
return this.record.data;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Sets additional data for this Opportunity.
|
|
228
|
+
* @param {Object} data - The data to set for the Opportunity.
|
|
229
|
+
* @returns {Opportunity} - The current instance of Opportunity for chaining.
|
|
230
|
+
* @throws {Error} - Throws an error if the data is not a valid object.
|
|
231
|
+
*/
|
|
232
|
+
setData(data) {
|
|
233
|
+
this.patcher.patchValue('data', data);
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export default Opportunity;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { hasText } from '@adobe/spacecat-shared-utils';
|
|
14
|
+
|
|
15
|
+
import BaseCollection from './base.collection.js';
|
|
16
|
+
import Suggestion from './suggestion.model.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* SuggestionCollection - A collection class responsible for managing Suggestion entities.
|
|
20
|
+
* Extends the BaseCollection to provide specific methods for interacting with Suggestion records.
|
|
21
|
+
*
|
|
22
|
+
* @class SuggestionCollection
|
|
23
|
+
* @extends BaseCollection
|
|
24
|
+
*/
|
|
25
|
+
class SuggestionCollection extends BaseCollection {
|
|
26
|
+
/**
|
|
27
|
+
* Constructs an instance of SuggestionCollection. Tells the base class which model to use.
|
|
28
|
+
* @constructor
|
|
29
|
+
* @param {Object} service - The ElectroDB service instance used to manage Suggestion entities.
|
|
30
|
+
* @param {Object} modelFactory - A factory for creating model instances.
|
|
31
|
+
* @param {Object} log - A logger for capturing logging information.
|
|
32
|
+
*/
|
|
33
|
+
constructor(service, modelFactory, log) {
|
|
34
|
+
super(service, modelFactory, Suggestion, log);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves all Suggestion entities by their associated Opportunity ID.
|
|
39
|
+
* @async
|
|
40
|
+
* @param {string} opportunityId - The unique identifier of the associated Opportunity.
|
|
41
|
+
* @returns {Promise<Array<Suggestion>>} - A promise that resolves to an array of Suggestion
|
|
42
|
+
* instances related to the given Opportunity ID.
|
|
43
|
+
* @throws {Error} - Throws an error if the opportunityId is not provided or if the query fails.
|
|
44
|
+
*/
|
|
45
|
+
async allByOpportunityId(opportunityId) {
|
|
46
|
+
if (!hasText(opportunityId)) {
|
|
47
|
+
throw new Error('OpportunityId is required');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const records = await this.entity.query.byOpportunityId({ opportunityId }).go();
|
|
51
|
+
|
|
52
|
+
return this._createInstances(records);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves all Suggestion entities by their associated Opportunity ID and status.
|
|
57
|
+
* @param {string} opportunityId - The unique identifier of the associated Opportunity.
|
|
58
|
+
* @param {string} status - The status of the Suggestion entities
|
|
59
|
+
* @return {Promise<Array<BaseModel>>} - A promise that resolves to an array of
|
|
60
|
+
* Suggestion instances.
|
|
61
|
+
* @throws {Error} - Throws an error if the opportunityId or status is not provided.
|
|
62
|
+
*/
|
|
63
|
+
async allByOpportunityIdAndStatus(opportunityId, status) {
|
|
64
|
+
if (!hasText(opportunityId)) {
|
|
65
|
+
throw new Error('OpportunityId is required');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!hasText(status)) {
|
|
69
|
+
throw new Error('Status is required');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const records = await this.entity.query.byOpportunityIdAndStatus(
|
|
73
|
+
{ opportunityId, status },
|
|
74
|
+
).go();
|
|
75
|
+
|
|
76
|
+
return this._createInstances(records);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default SuggestionCollection;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import BaseModel from './base.model.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Suggestion - A class representing a Suggestion entity.
|
|
17
|
+
* Provides methods to access and manipulate Suggestion-specific data,
|
|
18
|
+
* such as related opportunities, types, statuses, etc.
|
|
19
|
+
*
|
|
20
|
+
* @class Suggestion
|
|
21
|
+
* @extends BaseModel
|
|
22
|
+
*/
|
|
23
|
+
class Suggestion extends BaseModel {
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the Opportunity entity associated to this Suggestion.
|
|
26
|
+
* @async
|
|
27
|
+
* @returns {Promise<Opportunity>} - A promise that resolves to the Opportunity
|
|
28
|
+
* instance associated with this Suggestion.
|
|
29
|
+
*/
|
|
30
|
+
async getOpportunity() {
|
|
31
|
+
return this._getAssociation('OpportunityCollection', 'findById', this.getOpportunityId());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Gets the Opportunity ID for this Suggestion.
|
|
36
|
+
* @returns {string} - The unique identifier of the related Opportunity.
|
|
37
|
+
*/
|
|
38
|
+
getOpportunityId() {
|
|
39
|
+
return this.record.opportunityId;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Sets the Opportunity ID for this Suggestion.
|
|
44
|
+
* @param {string} opportunityId - The unique identifier of the related Opportunity.
|
|
45
|
+
* @returns {Suggestion} - The current instance of Suggestion for chaining.
|
|
46
|
+
* @throws {Error} - Throws an error if the opportunityId is not a valid UUID.
|
|
47
|
+
*/
|
|
48
|
+
setOpportunityId(opportunityId) {
|
|
49
|
+
this.patcher.patchValue('opportunityId', opportunityId, true);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Gets the type of this Suggestion.
|
|
55
|
+
* @returns {string} - The type of the Suggestion (e.g., CODE_CHANGE, CONTENT_UPDATE).
|
|
56
|
+
*/
|
|
57
|
+
getType() {
|
|
58
|
+
return this.record.type;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Gets the status of this Suggestion.
|
|
63
|
+
* @returns {string} - The status of the Suggestion (e.g., NEW, APPROVED, SKIPPED, FIXED, ERROR).
|
|
64
|
+
*/
|
|
65
|
+
getStatus() {
|
|
66
|
+
return this.record.status;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Sets the status of this Suggestion. Check the schema for possible values.
|
|
71
|
+
* @param {string} status - The new status of the Suggestion.
|
|
72
|
+
* @returns {Suggestion} - The current instance of Suggestion for chaining.
|
|
73
|
+
* @throws {Error} - Throws an error if the status is not a valid value.
|
|
74
|
+
*/
|
|
75
|
+
setStatus(status) {
|
|
76
|
+
this.patcher.patchValue('status', status);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Gets the rank of this Suggestion.
|
|
82
|
+
* @returns {number} - The rank of the Suggestion used for sorting or prioritization.
|
|
83
|
+
*/
|
|
84
|
+
getRank() {
|
|
85
|
+
return this.record.rank;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Sets the rank of this Suggestion.
|
|
90
|
+
* @param {number} rank - The rank value to set for this Suggestion.
|
|
91
|
+
* @returns {Suggestion} - The current instance of Suggestion for chaining.
|
|
92
|
+
* @throws {Error} - Throws an error if the rank is not a valid number.
|
|
93
|
+
*/
|
|
94
|
+
setRank(rank) {
|
|
95
|
+
this.patcher.patchValue('rank', rank);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Gets additional data associated with this Suggestion.
|
|
101
|
+
* @returns {Object} - The additional data for the Suggestion.
|
|
102
|
+
*/
|
|
103
|
+
getData() {
|
|
104
|
+
return this.record.data;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Sets additional data for this Suggestion.
|
|
109
|
+
* @param {Object} data - The data to set for the Suggestion.
|
|
110
|
+
* @returns {Suggestion} - The current instance of Suggestion for chaining.
|
|
111
|
+
* @throws {Error} - Throws an error if the data is not a valid object.
|
|
112
|
+
*/
|
|
113
|
+
setData(data) {
|
|
114
|
+
this.patcher.patchValue('data', data);
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Gets the KPI deltas for this Suggestion.
|
|
120
|
+
* @returns {Object} - The key performance indicator deltas that are affected by this Suggestion.
|
|
121
|
+
*/
|
|
122
|
+
getKpiDeltas() {
|
|
123
|
+
return this.record.kpiDeltas;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Sets the KPI deltas for this Suggestion.
|
|
128
|
+
* @param {Object} kpiDeltas - The KPI deltas to set for the Suggestion.
|
|
129
|
+
* @returns {Suggestion} - The current instance of Suggestion for chaining.
|
|
130
|
+
* @throws {Error} - Throws an error if the kpiDeltas is not a valid object.
|
|
131
|
+
*/
|
|
132
|
+
setKpiDeltas(kpiDeltas) {
|
|
133
|
+
this.patcher.patchValue('kpiDeltas', kpiDeltas);
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export default Suggestion;
|