Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/spacecat-shared-data-access/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ export interface Site {
isLive: () => boolean;
setAudits: (audits: Audit[]) => Site;
toggleLive: () => Site;
updateGitHubURL: (gitHubURL: string) => Site;
updateImsOrgId: (imsOrgId: string) => Site;
}

export interface DataAccess {
getAuditsForSite: (
siteId: string,
auditType?: string
auditType?: string,
ascending?: boolean,
) => Promise<Audit[]>;
getLatestAuditForSite: (
siteId: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/

import { isObject } from '@adobe/spacecat-shared-utils';
import { hasText, isObject } from '@adobe/spacecat-shared-utils';

import { AuditDto } from '../../dto/audit.js';
import { createAudit } from '../../models/audit.js';
Expand All @@ -24,19 +24,29 @@ import { createAudit } from '../../models/audit.js';
* @param {Logger} log - The logger.
* @param {string} siteId - The ID of the site for which audits are being retrieved.
* @param {string} [auditType] - Optional. The type of audits to retrieve.
* @param {boolean} [ascending] - Optional. Determines if the audits should be sorted
* ascending. Default is true.
* @returns {Promise<Readonly<Audit>[]>} A promise that resolves to an array of audits
* for the specified site.
*/
export const getAuditsForSite = async (dynamoClient, config, log, siteId, auditType) => {
export const getAuditsForSite = async (
dynamoClient,
config,
log,
siteId,
auditType,
ascending = true,
) => {
const queryParams = {
TableName: config.tableNameAudits,
KeyConditionExpression: 'siteId = :siteId',
ExpressionAttributeValues: {
':siteId': siteId,
},
ScanIndexForward: ascending, // Sorts ascending if true, descending if false
};

if (auditType !== undefined) {
if (hasText(auditType)) {
queryParams.KeyConditionExpression += ' AND begins_with(SK, :auditType)';
queryParams.ExpressionAttributeValues[':auditType'] = `${auditType}#`;
}
Expand Down