|
5 | 5 | * how raw exported data is transformed into activities. |
6 | 6 | */ |
7 | 7 | import { getServiceChildLogger } from '@crowd/logging' |
8 | | -import { IActivityData, PlatformType } from '@crowd/types' |
| 8 | +import { IActivityData, IMemberData, MemberIdentityType, PlatformType } from '@crowd/types' |
9 | 9 |
|
10 | 10 | const log = getServiceChildLogger('transformer') |
11 | 11 |
|
@@ -38,6 +38,70 @@ export abstract class TransformerBase { |
38 | 38 | return TransformerBase.INDIVIDUAL_NO_ACCOUNT_RE.test(displayName.trim()) |
39 | 39 | } |
40 | 40 |
|
| 41 | + protected buildMemberIdentities(params: { |
| 42 | + email: string |
| 43 | + sourceId?: string |
| 44 | + platformUsername?: string | null |
| 45 | + lfUsername?: string | null |
| 46 | + }): IMemberData['identities'] { |
| 47 | + const { email, sourceId, platformUsername, lfUsername } = params |
| 48 | + const identities: IMemberData['identities'] = [ |
| 49 | + { |
| 50 | + platform: this.platform, |
| 51 | + value: email, |
| 52 | + type: MemberIdentityType.EMAIL, |
| 53 | + verified: true, |
| 54 | + verifiedBy: this.platform, |
| 55 | + sourceId, |
| 56 | + }, |
| 57 | + ] |
| 58 | + if (!lfUsername && !platformUsername) { |
| 59 | + identities.push({ |
| 60 | + platform: this.platform, |
| 61 | + value: email, |
| 62 | + type: MemberIdentityType.USERNAME, |
| 63 | + verified: true, |
| 64 | + verifiedBy: this.platform, |
| 65 | + sourceId, |
| 66 | + }) |
| 67 | + return identities |
| 68 | + } |
| 69 | + |
| 70 | + if (platformUsername) { |
| 71 | + identities.push({ |
| 72 | + platform: this.platform, |
| 73 | + value: platformUsername, |
| 74 | + type: MemberIdentityType.USERNAME, |
| 75 | + verified: true, |
| 76 | + verifiedBy: this.platform, |
| 77 | + sourceId, |
| 78 | + }) |
| 79 | + } |
| 80 | + |
| 81 | + if (lfUsername) { |
| 82 | + identities.push({ |
| 83 | + platform: PlatformType.LFID, |
| 84 | + value: lfUsername, |
| 85 | + type: MemberIdentityType.USERNAME, |
| 86 | + verified: true, |
| 87 | + verifiedBy: this.platform, |
| 88 | + sourceId, |
| 89 | + }) |
| 90 | + if (!platformUsername) { |
| 91 | + identities.push({ |
| 92 | + platform: this.platform, |
| 93 | + value: lfUsername, |
| 94 | + type: MemberIdentityType.USERNAME, |
| 95 | + verified: true, |
| 96 | + verifiedBy: this.platform, |
| 97 | + sourceId, |
| 98 | + }) |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + return identities |
| 103 | + } |
| 104 | + |
41 | 105 | /** |
42 | 106 | * Safe wrapper around transformRow that catches errors and returns null. |
43 | 107 | */ |
|
0 commit comments