Skip to content

Commit

Permalink
feat: site competitor entity
Browse files Browse the repository at this point in the history
  • Loading branch information
alinarublea committed Jan 10, 2025
1 parent 2cd886f commit baf9deb
Show file tree
Hide file tree
Showing 11 changed files with 477 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import LatestAuditCollection from '../latest-audit/latest-audit.collection.js';
import OpportunityCollection from '../opportunity/opportunity.collection.js';
import OrganizationCollection from '../organization/organization.collection.js';
import SiteCandidateCollection from '../site-candidate/site-candidate.collection.js';
import SiteCompetitorCollection from '../site-competitor/site-competitor.collection.js';
import SiteCollection from '../site/site.collection.js';
import SiteTopPageCollection from '../site-top-page/site-top-page.collection.js';
import SuggestionCollection from '../suggestion/suggestion.collection.js';
Expand All @@ -42,6 +43,7 @@ import SiteSchema from '../site/site.schema.js';
import SiteCandidateSchema from '../site-candidate/site-candidate.schema.js';
import SiteTopPageSchema from '../site-top-page/site-top-page.schema.js';
import SuggestionSchema from '../suggestion/suggestion.schema.js';
import SiteCompetitorSchema from '../site-competitor/site-competitor.schema.js';

/**
* EntityRegistry - A registry class responsible for managing entities, their schema and collection.
Expand Down Expand Up @@ -136,6 +138,7 @@ EntityRegistry.registerEntity(OpportunitySchema, OpportunityCollection);
EntityRegistry.registerEntity(OrganizationSchema, OrganizationCollection);
EntityRegistry.registerEntity(SiteSchema, SiteCollection);
EntityRegistry.registerEntity(SiteCandidateSchema, SiteCandidateCollection);
EntityRegistry.registerEntity(SiteCompetitorSchema, SiteCompetitorCollection);
EntityRegistry.registerEntity(SiteTopPageSchema, SiteTopPageCollection);
EntityRegistry.registerEntity(SuggestionSchema, SuggestionCollection);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import type { BaseCollection, BaseModel, Site } from '../index';

export interface SiteCompetitor extends BaseModel {
getBaseURL(): string;
getSite(): Promise<Site>;
getSiteId(): string;
getUpdatedBy(): string;
setBaseURL(baseURL: string): SiteCompetitor;
setSiteId(siteId: string): SiteCompetitor;
setUpdatedBy(updatedBy: string): SiteCompetitor;
}

export interface SiteCandidateCollection extends BaseCollection<SiteCompetitor> {
allByBaseURL(baseURL: string): Promise<SiteCompetitor[]>;
allBySiteId(siteId: string): Promise<SiteCompetitor[]>;
findByBaseURL(baseURL: string): Promise<SiteCompetitor | null>;
findBySiteId(siteId: string): Promise<SiteCompetitor | null>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import SiteCompetitor from './site-competitor.model.js';
import SiteCompetitorCollection from './site-competitor.collection.js';

export {
SiteCompetitor,
SiteCompetitorCollection,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import BaseCollection from '../base/base.collection.js';

/**
* SiteCompetitorCollection - A collection class responsible for managing SiteCompetitor entities.
* Extends the BaseCollection to provide specific methods for interacting with
* SiteCompetitor records.
*
* @class SiteCompetitorCollection
* @extends BaseCollection
*/
class SiteCompetitorCollection extends BaseCollection {
}

export default SiteCompetitorCollection;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import BaseModel from '../base/base.model.js';

/**
* SiteCandidate - A class representing an SiteCompetitor entity.
* Provides methods to access and manipulate SiteCompetitor-specific data.
*
* @class SiteCompetitor
* @extends BaseModel
*/
class SiteCompetitor extends BaseModel {

}

export default SiteCompetitor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/* c8 ignore start */
import { isValidUrl } from '@adobe/spacecat-shared-utils';

import { validate as uuidValidate } from 'uuid';

import SchemaBuilder from '../base/schema.builder.js';
import SiteCompetitor from './site-competitor.model.js';
import SiteCompetitorCollection from './site-competitor.collection.js';

/*
Schema Doc: https://electrodb.dev/en/modeling/schema/
Attribute Doc: https://electrodb.dev/en/modeling/attributes/
Indexes Doc: https://electrodb.dev/en/modeling/indexes/
*/

const schema = new SchemaBuilder(SiteCompetitor, SiteCompetitorCollection)
.addReference('belongs_to', 'Site')
.addAttribute('siteId', {
type: 'string',
validate: (value) => !value || uuidValidate(value),
})
.addAttribute('baseURL', {
type: 'string',
required: true,
validate: (value) => isValidUrl(value),
})
.addAttribute('updatedBy', {
type: 'string',
})
.addAllIndex(['baseURL'])
.addIndex(
{ composite: ['siteId'] },
{ composite: ['updatedAt'] },
);

/* c8 ignore stop */

export default schema.build();
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import keyEvents from './key-events.fixture.js';
import opportunities from './opportunities.fixture.js';
import organizations from './organizations.fixture.js';
import siteCandidates from './site-candidates.fixture.js';
import siteCompetitors from './site-competitor.fixture.js';
import siteTopPages from './site-top-pages.fixture.js';
import sites from './sites.fixture.js';
import suggestions from './suggestions.fixture.js';
Expand All @@ -35,6 +36,7 @@ export default {
opportunities,
organizations,
siteCandidates,
siteCompetitors,
siteTopPages,
sites,
suggestions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright 2025 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

const siteCompetitors = [
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440000',
baseURL: 'https://competitor1.com',
siteId: '78fec9c7-2141-4600-b7b1-ea5c78752b91',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440001',
baseURL: 'https://competitor2.com',
siteId: '78fec9c7-2141-4600-b7b1-ea5c78752b91',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440002',
baseURL: 'https://competitor3.com',
siteId: '78fec9c7-2141-4600-b7b1-ea5c78752b91',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440003',
baseURL: 'https://competitor4.com',
siteId: '78fec9c7-2141-4600-b7b1-ea5c78752b91',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440004',
baseURL: 'https://competitor5.com',
siteId: '78fec9c7-2141-4600-b7b1-ea5c78752b91',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440005',
baseURL: 'https://competitor6.com',
siteId: '78fec9c7-2141-4600-b7b1-ea5c78752b91',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440006',
baseURL: 'https://competitor7.com',
siteId: '78fec9c7-2141-4600-b7b1-ea5c78752b91',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440007',
baseURL: 'https://competitor8.com',
siteId: '78fec9c7-2141-4600-b7b1-ea5c78752b91',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440008',
baseURL: 'https://competitor9.com',
siteId: '78fec9c7-2141-4600-b7b1-ea5c78752b91',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440009',
baseURL: 'https://competitor10.com',
siteId: 'b1ec63c4-87de-4500-bbc9-276039e4bc10',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440010',
baseURL: 'https://competitor11.com',
siteId: 'b1ec63c4-87de-4500-bbc9-276039e4bc10',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440011',
baseURL: 'https://competitor12.com',
siteId: 'b1ec63c4-87de-4500-bbc9-276039e4bc10',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440012',
baseURL: 'https://competitor13.com',
siteId: 'b1ec63c4-87de-4500-bbc9-276039e4bc10',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440013',
baseURL: 'https://competitor14.com',
siteId: 'b1ec63c4-87de-4500-bbc9-276039e4bc10',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440014',
baseURL: 'https://competitor15.com',
siteId: 'b1ec63c4-87de-4500-bbc9-276039e4bc10',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440015',
baseURL: 'https://competitor16.com',
siteId: 'b1ec63c4-87de-4500-bbc9-276039e4bc10',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440016',
baseURL: 'https://competitor17.com',
siteId: 'b1ec63c4-87de-4500-bbc9-276039e4bc10',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
siteCompetitorId: '550e8400-e29b-41d4-a716-446655440017',
baseURL: 'https://competitor18.com',
siteId: 'b1ec63c4-87de-4500-bbc9-276039e4bc10',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
];

export default siteCompetitors;
Loading

0 comments on commit baf9deb

Please sign in to comment.