-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
This PR will trigger a minor release when merged. |
There was a problem hiding this 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), |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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();
}
Please ensure your pull request adheres to the following guidelines:
Related Issues
Thanks for contributing!