@adobe/spacecat-shared-data-access 1.2.5 → 1.2.7

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.2.7](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.2.6...@adobe/spacecat-shared-data-access-v1.2.7) (2023-12-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * sort order sites with latest audits ([#46](https://github.com/adobe-rnd/spacecat-shared/issues/46)) ([8da2bf1](https://github.com/adobe-rnd/spacecat-shared/commit/8da2bf16b904ced6787d8c56ba2b4b72678687a0))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v1.2.6](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.2.5...@adobe/spacecat-shared-data-access-v1.2.6) (2023-12-11)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * include sites without latest audits ([#45](https://github.com/adobe-rnd/spacecat-shared/issues/45)) ([b843190](https://github.com/adobe-rnd/spacecat-shared/commit/b843190da09916832a743d6fc4bf83e804b61912))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v1.2.5](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.2.4...@adobe/spacecat-shared-data-access-v1.2.5) (2023-12-10)
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.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -55,16 +55,18 @@ export const getSitesToAudit = async (dynamoClient, config) => {
55
55
  };
56
56
 
57
57
  /**
58
- * Retrieves sites with their latest audit of a specified type.
59
- *
58
+ * Retrieves all sites with their latest audit. Sites without a latest audit will be included
59
+ * in the result, but will have an empty audits array. The sites are sorted by their latest
60
+ * audit scores in ascending order by default. The sortAuditsAscending parameter can be used
61
+ * to change the sort order. If a site has no latest audit, it will be sorted at the end of
62
+ * the list.
60
63
  * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
61
64
  * @param {DataAccessConfig} config - The data access config.
62
65
  * @param {Logger} log - The logger.
63
- * @param {string} auditType - The type of the latest audits to retrieve for each site.
64
- * @param {boolean} [sortAuditsAscending] - Optional. Determines if the audits
65
- * should be sorted ascending or descending by scores.
66
- * @returns {Promise<Readonly<Site>[]>} A promise that resolves to an array of site objects,
67
- * each with its latest audit of the specified type.
66
+ * @param {string} auditType - The type of audits to retrieve for the sites.
67
+ * @param {boolean} [sortAuditsAscending=true] - Determines if the audits should be sorted in
68
+ * @return {Promise<Readonly<Site>[]>} A promise that resolves to an array of sites with their
69
+ * latest audit.
68
70
  */
69
71
  export const getSitesWithLatestAudit = async (
70
72
  dynamoClient,
@@ -79,15 +81,25 @@ export const getSitesWithLatestAudit = async (
79
81
  ]);
80
82
 
81
83
  const sitesMap = new Map(sites.map((site) => [site.getId(), site]));
84
+ const orderedSites = [];
82
85
 
83
- return latestAudits.reduce((result, audit) => {
86
+ // First, append sites with a latest audit in the sorted order
87
+ latestAudits.forEach((audit) => {
84
88
  const site = sitesMap.get(audit.getSiteId());
85
89
  if (site) {
86
90
  site.setAudits([audit]);
87
- result.push(site);
91
+ orderedSites.push(site);
92
+ sitesMap.delete(site.getId()); // Remove the site from the map to avoid adding it again
88
93
  }
89
- return result;
90
- }, []);
94
+ });
95
+
96
+ // Then, append the remaining sites (without a latest audit)
97
+ sitesMap.forEach((site) => {
98
+ site.setAudits([]);
99
+ orderedSites.push(site);
100
+ });
101
+
102
+ return orderedSites;
91
103
  };
92
104
 
93
105
  /**