Skip to content
Draft
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
65 changes: 3 additions & 62 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build": "hedy -v --test-bundle",
"deploy": "hedy -v --deploy --aws-deploy-bucket=spacecat-prod-deploy --pkgVersion=latest",
"deploy-stage": "hedy -v --deploy --aws-deploy-bucket=spacecat-stage-deploy --pkgVersion=latest",
"deploy-dev": "hedy -v --deploy --pkgVersion=latest$CI_BUILD_NUM -l latest --aws-deploy-bucket=spacecat-dev-deploy --cleanup-ci=24h --aws-api vldld6qz1d",
"deploy-dev": "hedy -v --deploy --pkgVersion=latest$CI_BUILD_NUM -l sandsinh --aws-deploy-bucket=spacecat-dev-deploy --cleanup-ci=24h --aws-api vldld6qz1d",
"deploy-secrets": "hedy --aws-update-secrets --params-file=secrets/secrets.env",
"docs": "npm run docs:lint && npm run docs:build",
"docs:build": "npx @redocly/cli build-docs -o ./docs/index.html --config docs/openapi/redocly-config.yaml",
Expand Down Expand Up @@ -74,7 +74,7 @@
"@adobe/spacecat-helix-content-sdk": "1.4.24",
"@adobe/spacecat-shared-athena-client": "1.3.5",
"@adobe/spacecat-shared-brand-client": "1.1.24",
"@adobe/spacecat-shared-data-access": "2.65.2",
"@adobe/spacecat-shared-data-access": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-data-access?SITES-34129&t=20251004",
"@adobe/spacecat-shared-gpt-client": "1.6.5",
"@adobe/spacecat-shared-http-utils": "1.17.6",
"@adobe/spacecat-shared-ims-client": "1.8.13",
Expand Down
11 changes: 6 additions & 5 deletions src/controllers/fixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ export class FixesController {
const FixEntity = this.#FixEntity;
const fixes = await Promise.all(context.data.map(async (fixData, index) => {
try {
const fixEntity = await FixEntity.create({ ...fixData, opportunityId });
if (fixData.suggestionIds) {
await FixEntity.setSuggestionsByFixEntityId(fixEntity.getId(), fixData.suggestionIds);
}
return {
index,
fix: FixDto.toJSON(await FixEntity.create({ ...fixData, opportunityId })),
fix: FixDto.toJSON(fixEntity),
statusCode: 201,
};
} catch (error) {
Expand Down Expand Up @@ -326,10 +330,7 @@ export class FixesController {
if (suggestions.some((s) => !s || s.getOpportunityId() !== opportunityId)) {
return badRequest('Invalid suggestion IDs');
}
for (const suggestion of suggestions) {
suggestion.setFixEntityId(fixId);
}
await Promise.all(suggestions.map((s) => s.save()));
await this.#FixEntity.setSuggestionsByFixEntityId(fixId, suggestionIds);
hasUpdates = true;
}

Expand Down
41 changes: 41 additions & 0 deletions src/controllers/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {

import { ValidationError, Suggestion as SuggestionModel, Site as SiteModel } from '@adobe/spacecat-shared-data-access';
import { SuggestionDto } from '../dto/suggestion.js';
import { FixDto } from '../dto/fix.js';
import { sendAutofixMessage, getCSPromiseToken, ErrorWithStatusCode } from '../support/utils.js';
import AccessControlUtil from '../support/access-control-util.js';

Expand Down Expand Up @@ -329,6 +330,45 @@ function SuggestionsController(ctx, sqs, env) {
return badRequest('No updates provided');
};

/**
* Gets all fixes for a given suggestion
* @param {Object} context of the request
* @returns {Promise<Response>} Array of fixes response.
*/
const getSuggestionFixes = async (context) => {
const siteId = context.params?.siteId;
const opportunityId = context.params?.opportunityId;
const suggestionId = context.params?.suggestionId;

if (!isValidUUID(siteId)) {
return badRequest('Site ID required');
}

if (!isValidUUID(opportunityId)) {
return badRequest('Opportunity ID required');
}

if (!isValidUUID(suggestionId)) {
return badRequest('Suggestion ID required');
}

try {
const site = await Site.findById(siteId);
if (!site) {
return notFound('Site not found');
}

if (!await accessControlUtil.hasAccess(site)) {
return forbidden('User does not belong to the organization');
}

const fixes = await Suggestion.getFixEntitiesBySuggestionId(suggestionId);
return ok({ data: fixes.map((fix) => FixDto.toJSON(fix)) });
} catch (error) {
return createResponse({ message: 'Error retrieving fixes for suggestion' }, 500);
}
};

/**
* Update the status of one or multiple suggestions in one transaction
* @param {Object} context of the request
Expand Down Expand Up @@ -663,6 +703,7 @@ function SuggestionsController(ctx, sqs, env) {
getAllForOpportunity,
getByID,
getByStatus,
getSuggestionFixes,
patchSuggestion,
patchSuggestionsStatus,
removeSuggestion,
Expand Down
1 change: 1 addition & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export default function getRouteHandlers(
'PATCH /sites/:siteId/opportunities/:opportunityId/suggestions/auto-fix': suggestionsController.autofixSuggestions,
'GET /sites/:siteId/opportunities/:opportunityId/suggestions/by-status/:status': suggestionsController.getByStatus,
'GET /sites/:siteId/opportunities/:opportunityId/suggestions/:suggestionId': suggestionsController.getByID,
'GET /sites/:siteId/opportunities/:opportunityId/suggestions/:suggestionId/fixes': suggestionsController.getSuggestionFixes,
'POST /sites/:siteId/opportunities/:opportunityId/suggestions': suggestionsController.createSuggestions,
'PATCH /sites/:siteId/opportunities/:opportunityId/suggestions/status': suggestionsController.patchSuggestionsStatus,
'PATCH /sites/:siteId/opportunities/:opportunityId/suggestions/:suggestionId': suggestionsController.patchSuggestion,
Expand Down
Loading