Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add site competitors array to site entity #557

Open
wants to merge 37 commits into
base: main
Choose a base branch
from

Conversation

alinarublea
Copy link
Contributor

Please ensure your pull request adheres to the following guidelines:

  • make sure to link the related issues in this description
  • when merging / squashing, make sure the fixed issue references are visible in the commits, for easy compilation of release notes

Related Issues

Thanks for contributing!

Copy link

This PR will trigger a minor release when merged.

Copy link
Member

@solaris007 solaris007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not sure the collection methods are optimal, as modifying competitors is a record-, not collection-level concern. also, i think the management of the competitors list should be done outside the data layer. possibly the schema could validate that there's no duplicates (with the Set apporach).

.addAttribute('siteCompetitors', {
type: 'list',
default: [],
validate: (value) => Array.isArray(value),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the attribute is not required, we should not check for array unless a value is present.

}
const currentSiteCompetitors = site.getSiteCompetitors();
if (!currentSiteCompetitors.includes(siteCompetitorBaseURL)) {
currentSiteCompetitors.push(siteCompetitorBaseURL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not work, you'd have to call site.setSiteCompetitors(updatedCompetitors) - please validate in IT test

also, you could use a set to make things easier:

  const competitors = new Set(site.getSiteCompetitors());
  if (!competitors.has(siteCompetitorBaseURL)) {
    competitors.add(siteCompetitorBaseURL);
    site.setSiteCompetitors([...competitors]);
    await site.save();
  }

const currentSiteCompetitors = site.getSiteCompetitors();
const indexOfSiteCompetitor = currentSiteCompetitors.indexOf(siteCompetitorBaseURL);
if (indexOfSiteCompetitor !== -1) {
currentSiteCompetitors.splice(indexOfSiteCompetitor, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not work, you'd have to call site.setSiteCompetitors(updatedCompetitors) - please validate in IT test

you could use a set to make things easier:

  const competitors = new Set(site.getSiteCompetitors());
  if (competitors.has(siteCompetitorBaseURL)) {
    competitors.delete(siteCompetitorBaseURL);
    site.setSiteCompetitors([...competitors]);
    await site.save();
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants