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