|
| 1 | +import { COMMITTEES_GRID, CommitteesActivityType } from '@crowd/integrations' |
| 2 | +import { getServiceChildLogger } from '@crowd/logging' |
| 3 | +import { |
| 4 | + IActivityData, |
| 5 | + IMemberData, |
| 6 | + IOrganizationIdentity, |
| 7 | + MemberIdentityType, |
| 8 | + OrganizationIdentityType, |
| 9 | + OrganizationSource, |
| 10 | + PlatformType, |
| 11 | +} from '@crowd/types' |
| 12 | + |
| 13 | +import { TransformedActivity, TransformerBase } from '../../../core/transformerBase' |
| 14 | + |
| 15 | +const log = getServiceChildLogger('committeesCommitteesTransformer') |
| 16 | + |
| 17 | +export class CommitteesCommitteesTransformer extends TransformerBase { |
| 18 | + readonly platform = PlatformType.COMMITTEES |
| 19 | + |
| 20 | + transformRow(row: Record<string, unknown>): TransformedActivity | null { |
| 21 | + const email = (row.CONTACTEMAIL__C as string | null)?.trim() || null |
| 22 | + if (!email) { |
| 23 | + log.warn( |
| 24 | + { sfid: row.SFID, committeeId: row.COMMITTEE_ID, rawEmail: row.CONTACTEMAIL__C }, |
| 25 | + 'Skipping row: missing email', |
| 26 | + ) |
| 27 | + return null |
| 28 | + } |
| 29 | + |
| 30 | + const committeeId = (row.COMMITTEE_ID as string).trim() |
| 31 | + const fivetranDeleted = row.FIVETRAN_DELETED as boolean |
| 32 | + const lfUsername = (row.LF_USERNAME as string | null)?.trim() || null |
| 33 | + const suFullName = (row.SU_FULL_NAME as string | null)?.trim() || null |
| 34 | + const suFirstName = (row.SU_FIRST_NAME as string | null)?.trim() || null |
| 35 | + const suLastName = (row.SU_LAST_NAME as string | null)?.trim() || null |
| 36 | + |
| 37 | + const displayName = |
| 38 | + suFullName || |
| 39 | + (suFirstName && suLastName ? `${suFirstName} ${suLastName}` : suFirstName || suLastName) || |
| 40 | + email.split('@')[0] |
| 41 | + |
| 42 | + const type = fivetranDeleted |
| 43 | + ? CommitteesActivityType.REMOVED_FROM_COMMITTEE |
| 44 | + : CommitteesActivityType.ADDED_TO_COMMITTEE |
| 45 | + |
| 46 | + const identities: IMemberData['identities'] = [] |
| 47 | + |
| 48 | + if (lfUsername) { |
| 49 | + identities.push( |
| 50 | + { |
| 51 | + platform: PlatformType.COMMITTEES, |
| 52 | + value: email, |
| 53 | + type: MemberIdentityType.EMAIL, |
| 54 | + verified: true, |
| 55 | + verifiedBy: PlatformType.COMMITTEES, |
| 56 | + }, |
| 57 | + { |
| 58 | + platform: PlatformType.COMMITTEES, |
| 59 | + value: lfUsername, |
| 60 | + type: MemberIdentityType.USERNAME, |
| 61 | + verified: true, |
| 62 | + verifiedBy: PlatformType.COMMITTEES, |
| 63 | + }, |
| 64 | + { |
| 65 | + platform: PlatformType.LFID, |
| 66 | + value: lfUsername, |
| 67 | + type: MemberIdentityType.USERNAME, |
| 68 | + verified: true, |
| 69 | + verifiedBy: PlatformType.COMMITTEES, |
| 70 | + }, |
| 71 | + ) |
| 72 | + } |
| 73 | + |
| 74 | + if (!lfUsername) { |
| 75 | + identities.push({ |
| 76 | + platform: PlatformType.COMMITTEES, |
| 77 | + value: email, |
| 78 | + type: MemberIdentityType.USERNAME, |
| 79 | + verified: true, |
| 80 | + verifiedBy: PlatformType.COMMITTEES, |
| 81 | + }) |
| 82 | + } |
| 83 | + |
| 84 | + const activity: IActivityData = { |
| 85 | + type, |
| 86 | + platform: PlatformType.COMMITTEES, |
| 87 | + timestamp: (row.LASTMODIFIEDDATE as string | null) || null, |
| 88 | + score: COMMITTEES_GRID[type].score, |
| 89 | + sourceId: committeeId, |
| 90 | + sourceParentId: null, |
| 91 | + member: { |
| 92 | + displayName, |
| 93 | + identities, |
| 94 | + organizations: this.buildOrganizations(row), |
| 95 | + }, |
| 96 | + attributes: { |
| 97 | + committeeId: (row.COLLABORATION_NAME__C as string | null) || null, |
| 98 | + committeeName: (row.COMMITTEE_NAME as string | null) || null, |
| 99 | + role: (row.ROLE__C as string | null) || null, |
| 100 | + projectId: (row.PROJECT_ID as string | null) || null, |
| 101 | + projectName: (row.PROJECT_NAME as string | null) || null, |
| 102 | + organizationId: (row.ACCOUNT__C as string | null) || null, |
| 103 | + organizationName: (row.ACCOUNT_NAME as string | null) || null, |
| 104 | + member: { |
| 105 | + userId: (row.PRIMARY_SOURCE_USER_ID as string | null) || null, |
| 106 | + firstName: (row.SU_FIRST_NAME as string | null) || null, |
| 107 | + lastName: (row.SU_LAST_NAME as string | null) || null, |
| 108 | + email, |
| 109 | + }, |
| 110 | + actor: { |
| 111 | + userId: (row.CREATEDBYID as string | null) || null, |
| 112 | + firstName: (row.BU_FIRST_NAME as string | null) || null, |
| 113 | + lastName: (row.BU_LAST_NAME as string | null) || null, |
| 114 | + email: (row.BU_EMAIL as string | null) || null, |
| 115 | + }, |
| 116 | + activityDate: (row.CREATEDDATE as string | null) || null, |
| 117 | + }, |
| 118 | + } |
| 119 | + |
| 120 | + const segmentSlug = (row.PROJECT_SLUG as string | null)?.trim() || null |
| 121 | + const segmentSourceId = (row.PROJECT_ID as string | null)?.trim() || null |
| 122 | + |
| 123 | + if (!segmentSlug || !segmentSourceId) { |
| 124 | + log.warn( |
| 125 | + { sfid: row.SFID, committeeId, segmentSlug, segmentSourceId }, |
| 126 | + 'Skipping row: missing segment slug or sourceId', |
| 127 | + ) |
| 128 | + return null |
| 129 | + } |
| 130 | + |
| 131 | + return { activity, segment: { slug: segmentSlug, sourceId: segmentSourceId } } |
| 132 | + } |
| 133 | + |
| 134 | + private buildOrganizations(row: Record<string, unknown>): IActivityData['member']['organizations'] { |
| 135 | + const website = (row.ORG_WEBSITE as string | null)?.trim() || null |
| 136 | + const domainAliases = (row.ORG_DOMAIN_ALIASES as string | null)?.trim() || null |
| 137 | + |
| 138 | + if (!website && !domainAliases) { |
| 139 | + return undefined |
| 140 | + } |
| 141 | + |
| 142 | + const displayName = (row.ACCOUNT_NAME as string | null)?.trim() || website |
| 143 | + |
| 144 | + if (this.isIndividualNoAccount(displayName)) { |
| 145 | + return [ |
| 146 | + { |
| 147 | + displayName, |
| 148 | + source: OrganizationSource.COMMITTEES, |
| 149 | + identities: website |
| 150 | + ? [ |
| 151 | + { |
| 152 | + platform: PlatformType.COMMITTEES, |
| 153 | + value: website, |
| 154 | + type: OrganizationIdentityType.PRIMARY_DOMAIN, |
| 155 | + verified: true, |
| 156 | + }, |
| 157 | + ] |
| 158 | + : [], |
| 159 | + }, |
| 160 | + ] |
| 161 | + } |
| 162 | + |
| 163 | + const identities: IOrganizationIdentity[] = [] |
| 164 | + |
| 165 | + if (website) { |
| 166 | + identities.push({ |
| 167 | + platform: PlatformType.COMMITTEES, |
| 168 | + value: website, |
| 169 | + type: OrganizationIdentityType.PRIMARY_DOMAIN, |
| 170 | + verified: true, |
| 171 | + }) |
| 172 | + } |
| 173 | + |
| 174 | + if (domainAliases) { |
| 175 | + for (const alias of domainAliases.split(',')) { |
| 176 | + const trimmed = alias.trim() |
| 177 | + if (trimmed) { |
| 178 | + identities.push({ |
| 179 | + platform: PlatformType.COMMITTEES, |
| 180 | + value: trimmed, |
| 181 | + type: OrganizationIdentityType.ALTERNATIVE_DOMAIN, |
| 182 | + verified: true, |
| 183 | + }) |
| 184 | + } |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + return [ |
| 189 | + { |
| 190 | + displayName, |
| 191 | + source: OrganizationSource.COMMITTEES, |
| 192 | + identities, |
| 193 | + }, |
| 194 | + ] |
| 195 | + } |
| 196 | +} |
0 commit comments