-
Notifications
You must be signed in to change notification settings - Fork 731
fix: recalculate affiliations on update member orgs (IN-1083) #4039
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
Changes from all commits
fc72808
88b2969
277b047
ee5d81e
39dc845
2294c0d
3cc0797
eb78d2b
b65c266
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import { | |
| insertMemberSegmentAggregates, | ||
| queryMembersAdvanced, | ||
| } from '@crowd/data-access-layer/src/members' | ||
| import { fetchMemberOrganizations } from '@crowd/data-access-layer/src/members/organizations' | ||
| import { QueryExecutor, optionsQx } from '@crowd/data-access-layer/src/queryExecutor' | ||
| import { fetchManySegments } from '@crowd/data-access-layer/src/segments' | ||
| import { LoggerBase } from '@crowd/logging' | ||
|
|
@@ -276,6 +277,8 @@ export default class MemberService extends LoggerBase { | |
| data.displayName = data.username[data.platform].username | ||
| } | ||
|
|
||
| let existingOrgIds: string[] = [] | ||
|
|
||
| const transaction = await SequelizeRepository.createTransaction(this.options) | ||
|
|
||
| try { | ||
|
|
@@ -436,6 +439,13 @@ export default class MemberService extends LoggerBase { | |
| let record | ||
| if (existing) { | ||
| const { id } = existing | ||
|
|
||
| if (data.organizations) { | ||
| existingOrgIds = (await fetchMemberOrganizations(optionsQx(this.options), id)).map( | ||
| (o) => o.organizationId, | ||
| ) | ||
| } | ||
|
|
||
| delete existing.id | ||
| const toUpdate = CommonMemberService.membersMerge(existing, data) | ||
|
|
||
|
|
@@ -505,6 +515,21 @@ export default class MemberService extends LoggerBase { | |
|
|
||
| await SequelizeRepository.commitTransaction(transaction) | ||
|
|
||
| if (data.organizations) { | ||
| const commonMemberService = new CommonMemberService( | ||
| optionsQx(this.options), | ||
| this.options.temporal, | ||
| this.options.log, | ||
| ) | ||
| const newOrgIds = data.organizations.map((o) => o.id) | ||
|
ulemons marked this conversation as resolved.
|
||
| const allAffectedOrgIds = [...new Set([...existingOrgIds, ...newOrgIds])] | ||
| await commonMemberService.startAffiliationRecalculation( | ||
| record.id, | ||
| allAffectedOrgIds, | ||
| syncToOpensearch, | ||
| ) | ||
| } | ||
|
|
||
| if (syncToOpensearch) { | ||
| await searchSyncService.triggerMemberSync(record.id) | ||
| } | ||
|
|
@@ -800,6 +825,10 @@ export default class MemberService extends LoggerBase { | |
| ) { | ||
| let transaction | ||
| try { | ||
| const existingOrgIds = data.organizations | ||
| ? (await fetchMemberOrganizations(optionsQx(this.options), id)).map((o) => o.organizationId) | ||
| : [] | ||
|
|
||
| const repoOptions = await SequelizeRepository.createTransactionalRepositoryOptions( | ||
| this.options, | ||
| ) | ||
|
|
@@ -824,9 +853,11 @@ export default class MemberService extends LoggerBase { | |
| this.options.temporal, | ||
| this.options.log, | ||
| ) | ||
| const newOrgIds = (data.organizations || []).map((o) => o.id) | ||
|
ulemons marked this conversation as resolved.
ulemons marked this conversation as resolved.
|
||
| const allAffectedOrgIds = [...new Set([...existingOrgIds, ...newOrgIds])] | ||
| await commonMemberService.startAffiliationRecalculation( | ||
| id, | ||
| (data.organizations || []).map((o) => o.id), | ||
| allAffectedOrgIds, | ||
|
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. Unnecessary Temporal workflow on every member updateMedium Severity In the Reviewed by Cursor Bugbot for commit b65c266. Configure here. |
||
| syncToOpensearch, | ||
| ) | ||
|
|
||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.