Skip to content

Commit 8f7fe6d

Browse files
committed
feat: unify member identity building and cover missing cases
Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
1 parent b9c487a commit 8f7fe6d

1 file changed

Lines changed: 65 additions & 1 deletion

File tree

services/apps/snowflake_connectors/src/core/transformerBase.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* how raw exported data is transformed into activities.
66
*/
77
import { getServiceChildLogger } from '@crowd/logging'
8-
import { IActivityData, PlatformType } from '@crowd/types'
8+
import { IActivityData, IMemberData, MemberIdentityType, PlatformType } from '@crowd/types'
99

1010
const log = getServiceChildLogger('transformer')
1111

@@ -38,6 +38,70 @@ export abstract class TransformerBase {
3838
return TransformerBase.INDIVIDUAL_NO_ACCOUNT_RE.test(displayName.trim())
3939
}
4040

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+
41105
/**
42106
* Safe wrapper around transformRow that catches errors and returns null.
43107
*/

0 commit comments

Comments
 (0)