@@ -3,7 +3,7 @@ import lodash from 'lodash'
33import { Transaction } from 'sequelize'
44
55import { Error404 , sanitizeMemberOrganizationDateRange } from '@crowd/common'
6- import { CommonMemberService } from '@crowd/common_services'
6+ import { signalMemberUpdate } from '@crowd/common_services'
77import {
88 OrganizationField ,
99 changeMemberOrganizationAffiliationOverrides ,
@@ -14,7 +14,6 @@ import {
1414 fetchMemberOrganizationById ,
1515 fetchMemberOrganizations ,
1616 findMemberAffiliationOverrides ,
17- optionsQx ,
1817 queryOrgs ,
1918 updateMemberOrganization ,
2019} from '@crowd/data-access-layer'
@@ -36,16 +35,9 @@ type IOrganizationSummary = Pick<IOrganization, 'id' | 'displayName' | 'logo' |
3635export default class MemberOrganizationsService extends LoggerBase {
3736 options : IServiceOptions
3837
39- private readonly commonMemberService : CommonMemberService
40-
4138 constructor ( options : IServiceOptions ) {
4239 super ( options . log )
4340 this . options = options
44- this . commonMemberService = new CommonMemberService (
45- optionsQx ( options ) ,
46- options . temporal ,
47- options . log ,
48- )
4941 }
5042
5143 // Member organization list
@@ -196,13 +188,16 @@ export default class MemberOrganizationsService extends LoggerBase {
196188 ] )
197189 }
198190
199- // Start affiliation recalculation within the same transaction
200- await this . commonMemberService . startAffiliationRecalculation ( memberId , [ data . organizationId ] )
201-
202191 // Fetch updated list
203192 const result = await this . list ( memberId , transaction )
204193
205194 await SequelizeRepository . commitTransaction ( transaction )
195+
196+ // Signal after commit so the workflow sees persisted changes
197+ await signalMemberUpdate ( this . options . temporal , memberId , {
198+ memberOrganizationIds : [ data . organizationId ] ,
199+ } )
200+
206201 return result
207202 } catch ( error ) {
208203 await SequelizeRepository . rollbackTransaction ( transaction )
@@ -259,11 +254,15 @@ export default class MemberOrganizationsService extends LoggerBase {
259254 new Set ( [ existing . organizationId , data . organizationId ] ) ,
260255 ) . filter ( ( orgId ) : orgId is string => Boolean ( orgId ) )
261256
262- await this . commonMemberService . startAffiliationRecalculation ( memberId , orgsToRecalculate )
263-
264257 const result = await this . list ( memberId , transaction )
265258
266259 await SequelizeRepository . commitTransaction ( transaction )
260+
261+ // Signal after commit so the workflow sees persisted changes
262+ await signalMemberUpdate ( this . options . temporal , memberId , {
263+ memberOrganizationIds : orgsToRecalculate ,
264+ } )
265+
267266 return result
268267 } catch ( error ) {
269268 await SequelizeRepository . rollbackTransaction ( transaction )
@@ -288,15 +287,16 @@ export default class MemberOrganizationsService extends LoggerBase {
288287
289288 await deleteMemberOrganizations ( qx , memberId , [ id ] , true )
290289
291- await this . commonMemberService . startAffiliationRecalculation (
292- memberId ,
293- [ memberOrganizationToBeDeleted . organizationId ] ,
294- true ,
295- )
296-
297290 const result = await this . list ( memberId , transaction )
298291
299292 await SequelizeRepository . commitTransaction ( transaction )
293+
294+ // Signal after commit so the workflow sees persisted changes
295+ await signalMemberUpdate ( this . options . temporal , memberId , {
296+ memberOrganizationIds : [ memberOrganizationToBeDeleted . organizationId ] ,
297+ syncToOpensearch : true ,
298+ } )
299+
300300 return result
301301 } catch ( error ) {
302302 await SequelizeRepository . rollbackTransaction ( transaction )
0 commit comments