-
Notifications
You must be signed in to change notification settings - Fork 6
Add parent and strategicAlliances fields to Partner #3436
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: develop
Are you sure you want to change the base?
Changes from all commits
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 | ||
---|---|---|---|---|
|
@@ -41,6 +41,13 @@ module default { | |||
multi languagesOfConsulting: Language; | ||||
multi fieldRegions: FieldRegion; | ||||
multi countries: Location; | ||||
multi strategicAlliances: Partner { | ||||
constraint exclusive; | ||||
}; | ||||
|
||||
parent: Partner { | ||||
constraint exclusive; | ||||
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 means that a partner can only a parent to one other partner, which is not what you what. Multiple partners can share a single parent partner.
Suggested change
|
||||
}; | ||||
|
||||
startDate: cal::local_date; | ||||
|
||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -93,6 +93,8 @@ export class PartnerRepository extends DtoRepository(Partner) { | |||||||||||||||||||||||||||||
fieldRegions: ['FieldRegion', input.fieldRegions], | ||||||||||||||||||||||||||||||
countries: ['Location', input.countries], | ||||||||||||||||||||||||||||||
languagesOfConsulting: ['Language', input.languagesOfConsulting], | ||||||||||||||||||||||||||||||
strategicAlliances: ['Partner', input.strategicAlliances], | ||||||||||||||||||||||||||||||
parent: ['Partner', input.parentId], | ||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
rdonigian marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
.apply(departmentIdBlockUtils.createMaybe(input.departmentIdBlock)) | ||||||||||||||||||||||||||||||
|
@@ -118,11 +120,23 @@ export class PartnerRepository extends DtoRepository(Partner) { | |||||||||||||||||||||||||||||
countries, | ||||||||||||||||||||||||||||||
languagesOfConsulting, | ||||||||||||||||||||||||||||||
departmentIdBlock, | ||||||||||||||||||||||||||||||
strategicAlliances, | ||||||||||||||||||||||||||||||
parentId, | ||||||||||||||||||||||||||||||
...simpleChanges | ||||||||||||||||||||||||||||||
} = changes; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
await this.updateProperties({ id }, simpleChanges); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (parentId !== undefined) { | ||||||||||||||||||||||||||||||
if (parentId === id) { | ||||||||||||||||||||||||||||||
throw new InputException( | ||||||||||||||||||||||||||||||
'A partner cannot be its own parent organization', | ||||||||||||||||||||||||||||||
'partner.parent', | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+131
to
+136
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. Already done in the service
Suggested change
|
||||||||||||||||||||||||||||||
await this.updateRelation('parent', 'Partner', changes.id, parentId); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (pointOfContactId !== undefined) { | ||||||||||||||||||||||||||||||
await this.updateRelation( | ||||||||||||||||||||||||||||||
'pointOfContact', | ||||||||||||||||||||||||||||||
|
@@ -169,6 +183,26 @@ export class PartnerRepository extends DtoRepository(Partner) { | |||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (strategicAlliances) { | ||||||||||||||||||||||||||||||
if (strategicAlliances.includes(changes.id)) { | ||||||||||||||||||||||||||||||
throw new InputException( | ||||||||||||||||||||||||||||||
'A partner cannot be its own strategic ally', | ||||||||||||||||||||||||||||||
'partner.strategicAlliances', | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+187
to
+192
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.
Suggested change
|
||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||
await this.updateRelationList({ | ||||||||||||||||||||||||||||||
id: changes.id, | ||||||||||||||||||||||||||||||
relation: 'strategicAlliances', | ||||||||||||||||||||||||||||||
newList: strategicAlliances, | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
} catch (e) { | ||||||||||||||||||||||||||||||
throw e instanceof InputException | ||||||||||||||||||||||||||||||
? e.withField('partner.strategicAlliances') | ||||||||||||||||||||||||||||||
: e; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (languagesOfConsulting) { | ||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||
await this.updateRelationList({ | ||||||||||||||||||||||||||||||
|
@@ -257,6 +291,26 @@ export class PartnerRepository extends DtoRepository(Partner) { | |||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
.subQuery('node', (sub) => | ||||||||||||||||||||||||||||||
sub | ||||||||||||||||||||||||||||||
.match([ | ||||||||||||||||||||||||||||||
node('node'), | ||||||||||||||||||||||||||||||
relation('out', '', 'strategicAlliances'), | ||||||||||||||||||||||||||||||
node('strategicAlliances', 'Partner'), | ||||||||||||||||||||||||||||||
]) | ||||||||||||||||||||||||||||||
.return( | ||||||||||||||||||||||||||||||
collect('strategicAlliances { .id }').as('strategicAlliances'), | ||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
.subQuery('node', (sub) => | ||||||||||||||||||||||||||||||
sub | ||||||||||||||||||||||||||||||
.optionalMatch([ | ||||||||||||||||||||||||||||||
node('node'), | ||||||||||||||||||||||||||||||
relation('out', '', 'parent', ACTIVE), | ||||||||||||||||||||||||||||||
node('parent', 'Partner'), | ||||||||||||||||||||||||||||||
]) | ||||||||||||||||||||||||||||||
.return('parent { .id } as parent'), | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
Comment on lines
+305
to
+313
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.
Suggested change
|
||||||||||||||||||||||||||||||
.apply(matchProps()) | ||||||||||||||||||||||||||||||
.optionalMatch([ | ||||||||||||||||||||||||||||||
node('node'), | ||||||||||||||||||||||||||||||
|
@@ -288,6 +342,8 @@ export class PartnerRepository extends DtoRepository(Partner) { | |||||||||||||||||||||||||||||
departmentIdBlock: 'departmentIdBlock', | ||||||||||||||||||||||||||||||
scope: 'scopedRoles', | ||||||||||||||||||||||||||||||
pinned, | ||||||||||||||||||||||||||||||
parent: 'parent { .id }', | ||||||||||||||||||||||||||||||
strategicAlliances: 'strategicAlliances', | ||||||||||||||||||||||||||||||
}).as('dto'), | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,19 @@ export class PartnerService { | |
}; | ||
} | ||
|
||
if (input.strategicAlliances?.includes(input.id)) { | ||
throw new InputException( | ||
'A partner cannot be its own strategic ally', | ||
'partner.strategicAlliances', | ||
); | ||
} | ||
if (input.parentId && input.parentId === input.id) { | ||
throw new InputException( | ||
'A partner cannot be its own parent organization', | ||
'partner.parent', | ||
); | ||
} | ||
Comment on lines
+114
to
+125
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. Technically these constraints should apply on create() as well. |
||
|
||
const { departmentIdBlock, ...simpleInput } = input; | ||
const simpleChanges = this.repo.getActualChanges(partner, simpleInput); | ||
const changes = { | ||
|
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 means a partner can only be apart of one strategic alliance.
Are these alliances supposed to bi-directional? I think so.
Right now it is only unidirectional. "SC has an alliance with Wycliffe, but Wycliffe does not have an alliance with SC." That doesn't sound right.
"SC and Wycliffe have an alliance with each other" sounds more correct.
If that's true the implementation here would be different to accommodate.
Also are the alliances transient? A <-> B & B <-> C, meaning additionally A <-> C?