|
7 | 7 | } from '@crowd/common_services' |
8 | 8 | import { |
9 | 9 | QueryExecutor, |
| 10 | + changeMemberOrganizationAffiliationOverrides, |
| 11 | + checkOrganizationAffiliationPolicy, |
10 | 12 | createMemberOrganization, |
11 | 13 | fetchMemberOrganizationsBySource, |
12 | 14 | updateMemberOrganization, |
@@ -59,8 +61,7 @@ const job: IJobDefinition = { |
59 | 61 |
|
60 | 62 | if (changes.length > 0) { |
61 | 63 | ctx.log.debug({ memberId, changes }, 'Stint changes identified.') |
62 | | - // TODO: Uncomment after validating preview logs. |
63 | | - // await applyStintChanges(qx, changes) |
| 64 | + await applyStintChanges(qx, changes) |
64 | 65 | } |
65 | 66 | } |
66 | 67 |
|
@@ -107,12 +108,27 @@ function parseMemberActivityHash(hash: Record<string, string>) { |
107 | 108 | async function applyStintChanges(qx: QueryExecutor, changes: MemberOrgStintChange[]) { |
108 | 109 | for (const change of changes) { |
109 | 110 | if (change.type === 'insert') { |
110 | | - await createMemberOrganization(qx, change.memberId, { |
| 111 | + const memberOrganizationId = await createMemberOrganization(qx, change.memberId, { |
111 | 112 | organizationId: change.organizationId, |
112 | 113 | dateStart: change.dateStart, |
113 | 114 | dateEnd: change.dateEnd, |
114 | 115 | source: OrganizationSource.EMAIL_DOMAIN, |
115 | 116 | }) |
| 117 | + |
| 118 | + const isAffiliationBlocked = await checkOrganizationAffiliationPolicy( |
| 119 | + qx, |
| 120 | + change.organizationId, |
| 121 | + ) |
| 122 | + |
| 123 | + if (memberOrganizationId && isAffiliationBlocked) { |
| 124 | + await changeMemberOrganizationAffiliationOverrides(qx, [ |
| 125 | + { |
| 126 | + memberId: change.memberId, |
| 127 | + memberOrganizationId, |
| 128 | + allowAffiliation: false, |
| 129 | + }, |
| 130 | + ]) |
| 131 | + } |
116 | 132 | } else { |
117 | 133 | await updateMemberOrganization(qx, change.memberId, change.id, { |
118 | 134 | dateStart: change.dateStart, |
|
0 commit comments