-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add site competitors array to site entity #557
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
base: main
Are you sure you want to change the base?
Changes from all commits
317ca32
2ce1404
5c2390e
641f735
c9fc3d1
f007a5f
f09c2f6
966d79d
6136548
d7918e3
78baaae
cac54f9
3a34590
6073613
ad0bb8b
81204ae
2594513
f81d056
5354fc8
aaae74c
305a0a0
4eb43c3
835366c
f68704f
8371649
a1dac87
39f0a8d
8dc69f6
d6b853f
3299821
6c7c883
abbab5c
3f27400
904b1cc
0e0664c
d4ed2a6
4996666
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,33 @@ class SiteCollection extends BaseCollection { | |
|
||
return orderedSites; | ||
} | ||
|
||
async addSiteCompetitorBySiteId(siteId, siteCompetitorBaseURL) { | ||
const site = await this.findById(siteId); | ||
if (!site) { | ||
throw new DataAccessError(`Site with id ${siteId} not found`, this); | ||
} | ||
const currentSiteCompetitors = site.getSiteCompetitors(); | ||
if (!currentSiteCompetitors.includes(siteCompetitorBaseURL)) { | ||
currentSiteCompetitors.push(siteCompetitorBaseURL); | ||
await site.save(); | ||
} | ||
return site; | ||
} | ||
|
||
async removeSiteCompetitorBySiteId(siteId, siteCompetitorBaseURL) { | ||
const site = await this.findById(siteId); | ||
if (!site) { | ||
throw new DataAccessError(`Site with id ${siteId} not found`, this); | ||
} | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. this will not work, you'd have to call 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();
} |
||
await site.save(); | ||
} | ||
return site; | ||
} | ||
} | ||
|
||
export default SiteCollection; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,11 @@ const schema = new SchemaBuilder(Site, SiteCollection) | |
default: {}, | ||
validate: (value) => isObject(value), | ||
}) | ||
.addAttribute('siteCompetitors', { | ||
type: 'list', | ||
default: [], | ||
validate: (value) => Array.isArray(value), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
}) | ||
.addAttribute('isLive', { | ||
type: 'boolean', | ||
required: true, | ||
|
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 testalso, you could use a set to make things easier: