@adobe/spacecat-shared-data-access 1.1.3 → 1.1.5

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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [@adobe/spacecat-shared-data-access-v1.1.5](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.1.4...@adobe/spacecat-shared-data-access-v1.1.5) (2023-12-05)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * get audit no query ([#34](https://github.com/adobe-rnd/spacecat-shared/issues/34)) ([8fadd0a](https://github.com/adobe-rnd/spacecat-shared/commit/8fadd0a21a1e0cc232a06ccf805d1ac5c946b8be))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v1.1.4](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.1.3...@adobe/spacecat-shared-data-access-v1.1.4) (2023-12-05)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * latest-audits sort key ([#33](https://github.com/adobe-rnd/spacecat-shared/issues/33)) ([21dc14e](https://github.com/adobe-rnd/spacecat-shared/commit/21dc14e75e8aad641f1c99330243a3102e8de465))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v1.1.3](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.1.2...@adobe/spacecat-shared-data-access-v1.1.3) (2023-12-05)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -65,17 +65,12 @@ export const getAuditForSite = async (
65
65
  auditType,
66
66
  auditedAt,
67
67
  ) => {
68
- const audit = await dynamoClient.query({
69
- TableName: config.tableNameAudits,
70
- KeyConditionExpression: 'siteId = :siteId AND SK = :sk',
71
- ExpressionAttributeValues: {
72
- ':siteId': siteId,
73
- ':sk': `${auditType}#${auditedAt}`,
74
- },
75
- Limit: 1,
68
+ const audit = await dynamoClient.getItem(config.tableNameAudits, {
69
+ siteId,
70
+ SK: `${auditType}#${auditedAt}`,
76
71
  });
77
72
 
78
- return audit.length > 0 ? AuditDto.fromDynamoItem(audit[0]) : null;
73
+ return audit ? AuditDto.fromDynamoItem(audit) : null;
79
74
  };
80
75
 
81
76
  /**
@@ -158,10 +153,10 @@ export const getLatestAuditForSite = async (
158
153
  ) => {
159
154
  const latestAudit = await dynamoClient.query({
160
155
  TableName: config.tableNameLatestAudits,
161
- KeyConditionExpression: 'siteId = :siteId AND begins_with(SK, :auditType)',
156
+ KeyConditionExpression: 'siteId = :siteId AND auditType = :auditType',
162
157
  ExpressionAttributeValues: {
163
158
  ':siteId': siteId,
164
- ':auditType': `${auditType}#`,
159
+ ':auditType': `${auditType}`,
165
160
  },
166
161
  Limit: 1,
167
162
  });
@@ -221,13 +216,18 @@ async function removeAudits(
221
216
  ) {
222
217
  const tableName = latest ? config.tableNameLatestAudits : config.tableNameAudits;
223
218
  // TODO: use batch-remove (needs dynamo client update)
224
- const removeAuditPromises = audits.map((audit) => dynamoClient.removeItem(
225
- tableName,
226
- {
227
- siteId: audit.getSiteId(),
228
- SK: `${audit.getAuditType()}#${audit.getAuditedAt()}`,
229
- },
230
- ));
219
+ const removeAuditPromises = audits.map((audit) => {
220
+ const sortKey = latest
221
+ ? { auditType: `${audit.getAuditType()}` }
222
+ : { SK: `${audit.getAuditType()}#${audit.getAuditedAt()}` };
223
+ return dynamoClient.removeItem(
224
+ tableName,
225
+ {
226
+ siteId: audit.getSiteId(),
227
+ ...sortKey,
228
+ },
229
+ );
230
+ });
231
231
 
232
232
  await Promise.all(removeAuditPromises);
233
233
  }