@@ -27,7 +27,6 @@ import {
2727} from '@adobe/spacecat-shared-utils' ;
2828import { ValidationError } from '@adobe/spacecat-shared-data-access' ;
2929import { OpportunityDto } from '../dto/opportunity.js' ;
30- import { OpportunitySummaryDto } from '../dto/opportunity-summary.js' ;
3130import AccessControlUtil from '../support/access-control-util.js' ;
3231
3332/**
@@ -44,7 +43,7 @@ function OpportunitiesController(ctx) {
4443 if ( ! isNonEmptyObject ( dataAccess ) ) {
4544 throw new Error ( 'Data access required' ) ;
4645 }
47- const { Opportunity, Suggestion } = dataAccess ;
46+ const { Opportunity } = dataAccess ;
4847 if ( ! isObject ( Opportunity ) ) {
4948 throw new Error ( 'Opportunity Collection not available' ) ;
5049 }
@@ -312,70 +311,11 @@ function OpportunitiesController(ctx) {
312311 }
313312 } ;
314313
315- /**
316- * Gets top opportunities for paid media with 'NEW' or 'IN_PROGRESS' status for a site.
317- * @param {Object } context of the request
318- * @returns {Promise<Response> } Array of opportunity summaries.
319- */
320- const getTopPaidOpportunities = async ( context ) => {
321- const siteId = context . params ?. siteId ;
322-
323- if ( ! isValidUUID ( siteId ) ) {
324- return badRequest ( 'Site ID required' ) ;
325- }
326-
327- const site = await Site . findById ( siteId ) ;
328- if ( ! site ) {
329- return notFound ( 'Site not found' ) ;
330- }
331- if ( ! await accessControlUtil . hasAccess ( site ) ) {
332- return forbidden ( 'Only users belonging to the organization of the site can view its opportunities' ) ;
333- }
334-
335- const newOpportunities = await Opportunity . allBySiteIdAndStatus ( siteId , 'NEW' ) ;
336- const inProgressOpportunities = await Opportunity . allBySiteIdAndStatus ( siteId , 'IN_PROGRESS' ) ;
337- const allOpportunities = [ ...newOpportunities , ...inProgressOpportunities ] ;
338-
339- // temp using all these tags for testing but evenutally we will just use 'paid media'
340- const targetTags = [ 'paid media' , 'traffic acquisition' , 'engagement' , 'content optimization' ] ;
341- const filteredOpportunities = allOpportunities . filter ( ( oppty ) => {
342- const tags = oppty . getTags ( ) || [ ] ;
343- const title = oppty . getTitle ( ) || '' ;
344- const description = oppty . getDescription ( ) ;
345-
346- if ( ! description ) {
347- return false ;
348- }
349-
350- if ( title . toLowerCase ( ) . includes ( 'report' ) ) {
351- return false ;
352- }
353-
354- return tags . some ( ( tag ) => targetTags . includes ( tag . toLowerCase ( ) ) ) ;
355- } ) ;
356-
357- const opportunitySummaries = await Promise . all (
358- filteredOpportunities . map ( async ( oppty ) => {
359- const suggestions = await Suggestion . allByOpportunityId ( oppty . getId ( ) ) ;
360- return OpportunitySummaryDto . toJSON ( oppty , suggestions ) ;
361- } ) ,
362- ) ;
363-
364- const validSummaries = opportunitySummaries . filter (
365- ( summary ) => summary . projectedTrafficValue > 0 ,
366- ) ;
367-
368- validSummaries . sort ( ( a , b ) => b . projectedTrafficValue - a . projectedTrafficValue ) ;
369-
370- return ok ( validSummaries ) ;
371- } ;
372-
373314 return {
374315 createOpportunity,
375316 getAllForSite,
376317 getByID,
377318 getByStatus,
378- getTopPaidOpportunities,
379319 patchOpportunity,
380320 removeOpportunity,
381321 } ;
0 commit comments