Skip to content

Commit 678edcc

Browse files
committed
fix: avoid buildOrg duplication
1 parent 3a22b74 commit 678edcc

4 files changed

Lines changed: 69 additions & 162 deletions

File tree

services/apps/snowflake_connectors/src/integrations/tnc/certificates/transformer.ts

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@ import { getServiceChildLogger } from '@crowd/logging'
33
import {
44
IActivityData,
55
IMemberData,
6-
IOrganizationIdentity,
76
MemberAttributeName,
87
MemberIdentityType,
9-
OrganizationIdentityType,
10-
OrganizationSource,
118
PlatformType,
129
} from '@crowd/types'
1310

14-
import { TransformedActivity, TransformerBase } from '../../../core/transformerBase'
11+
import { TransformedActivity } from '../../../core/transformerBase'
12+
import { TncTransformerBase } from '../tncTransformerBase'
1513

1614
const log = getServiceChildLogger('tncCertificatesTransformer')
1715

18-
export class TncCertificatesTransformer extends TransformerBase {
19-
readonly platform = PlatformType.TNC
20-
16+
export class TncCertificatesTransformer extends TncTransformerBase {
2117
transformRow(row: Record<string, unknown>): TransformedActivity | null {
2218
const email = (row.USER_EMAIL as string | null)?.trim() || null
2319
if (!email) {
@@ -102,51 +98,4 @@ export class TncCertificatesTransformer extends TransformerBase {
10298

10399
return { activity, segment: { slug: segmentSlug, sourceId: segmentSourceId } }
104100
}
105-
106-
private buildOrganizations(
107-
row: Record<string, unknown>,
108-
): IActivityData['member']['organizations'] {
109-
const website = (row.ORG_WEBSITE as string | null)?.trim() || null
110-
const domainAliases = (row.ORG_DOMAIN_ALIASES as string | null)?.trim() || null
111-
112-
if (!website && !domainAliases) {
113-
return undefined
114-
}
115-
116-
const identities: IOrganizationIdentity[] = []
117-
118-
if (website) {
119-
identities.push({
120-
platform: PlatformType.TNC,
121-
value: website,
122-
type: OrganizationIdentityType.PRIMARY_DOMAIN,
123-
verified: true,
124-
})
125-
}
126-
127-
if (domainAliases) {
128-
for (const alias of domainAliases.split(',')) {
129-
const trimmed = alias.trim()
130-
if (trimmed) {
131-
identities.push({
132-
platform: PlatformType.TNC,
133-
value: trimmed,
134-
type: OrganizationIdentityType.ALTERNATIVE_DOMAIN,
135-
verified: true,
136-
})
137-
}
138-
}
139-
}
140-
141-
return [
142-
{
143-
displayName: (row.ORGANIZATION_NAME as string | null)?.trim() || website,
144-
source: OrganizationSource.TNC,
145-
identities,
146-
logo: (row.LOGO_URL as string | null)?.trim() || undefined,
147-
size: (row.ORGANIZATION_SIZE as string | null)?.trim() || undefined,
148-
industry: (row.ORGANIZATION_INDUSTRY as string | null)?.trim() || undefined,
149-
},
150-
]
151-
}
152101
}

services/apps/snowflake_connectors/src/integrations/tnc/courses/transformer.ts

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@ import { getServiceChildLogger } from '@crowd/logging'
33
import {
44
IActivityData,
55
IMemberData,
6-
IOrganizationIdentity,
76
MemberAttributeName,
87
MemberIdentityType,
9-
OrganizationIdentityType,
10-
OrganizationSource,
118
PlatformType,
129
} from '@crowd/types'
1310

14-
import { TransformedActivity, TransformerBase } from '../../../core/transformerBase'
11+
import { TransformedActivity } from '../../../core/transformerBase'
12+
import { TncTransformerBase } from '../tncTransformerBase'
1513

1614
const log = getServiceChildLogger('tncCoursesTransformer')
1715

18-
export class TncCoursesTransformer extends TransformerBase {
19-
readonly platform = PlatformType.TNC
20-
16+
export class TncCoursesTransformer extends TncTransformerBase {
2117
transformRow(row: Record<string, unknown>): TransformedActivity | null {
2218
const email = (row.USER_EMAIL as string | null)?.trim() || null
2319
if (!email) {
@@ -112,51 +108,4 @@ export class TncCoursesTransformer extends TransformerBase {
112108

113109
return { activity, segment: { slug: segmentSlug, sourceId: segmentSourceId } }
114110
}
115-
116-
private buildOrganizations(
117-
row: Record<string, unknown>,
118-
): IActivityData['member']['organizations'] {
119-
const website = (row.ORG_WEBSITE as string | null)?.trim() || null
120-
const domainAliases = (row.ORG_DOMAIN_ALIASES as string | null)?.trim() || null
121-
122-
if (!website && !domainAliases) {
123-
return undefined
124-
}
125-
126-
const identities: IOrganizationIdentity[] = []
127-
128-
if (website) {
129-
identities.push({
130-
platform: PlatformType.TNC,
131-
value: website,
132-
type: OrganizationIdentityType.PRIMARY_DOMAIN,
133-
verified: true,
134-
})
135-
}
136-
137-
if (domainAliases) {
138-
for (const alias of domainAliases.split(',')) {
139-
const trimmed = alias.trim()
140-
if (trimmed) {
141-
identities.push({
142-
platform: PlatformType.TNC,
143-
value: trimmed,
144-
type: OrganizationIdentityType.ALTERNATIVE_DOMAIN,
145-
verified: true,
146-
})
147-
}
148-
}
149-
}
150-
151-
return [
152-
{
153-
displayName: (row.ORGANIZATION_NAME as string | null)?.trim() || website,
154-
source: OrganizationSource.TNC,
155-
identities,
156-
logo: (row.LOGO_URL as string | null)?.trim() || undefined,
157-
size: (row.ORGANIZATION_SIZE as string | null)?.trim() || undefined,
158-
industry: (row.ORGANIZATION_INDUSTRY as string | null)?.trim() || undefined,
159-
},
160-
]
161-
}
162111
}

services/apps/snowflake_connectors/src/integrations/tnc/enrollments/transformer.ts

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@ import { getServiceChildLogger } from '@crowd/logging'
33
import {
44
IActivityData,
55
IMemberData,
6-
IOrganizationIdentity,
76
MemberAttributeName,
87
MemberIdentityType,
9-
OrganizationIdentityType,
10-
OrganizationSource,
118
PlatformType,
129
} from '@crowd/types'
1310

14-
import { TransformedActivity, TransformerBase } from '../../../core/transformerBase'
11+
import { TransformedActivity } from '../../../core/transformerBase'
12+
import { TncTransformerBase } from '../tncTransformerBase'
1513

1614
const log = getServiceChildLogger('tncEnrollmentsTransformer')
1715

18-
export class TncEnrollmentsTransformer extends TransformerBase {
19-
readonly platform = PlatformType.TNC
20-
16+
export class TncEnrollmentsTransformer extends TncTransformerBase {
2117
transformRow(row: Record<string, unknown>): TransformedActivity | null {
2218
const email = (row.USER_EMAIL as string | null)?.trim() || null
2319
if (!email) {
@@ -127,51 +123,4 @@ export class TncEnrollmentsTransformer extends TransformerBase {
127123

128124
return { activity, segment: { slug: segmentSlug, sourceId: segmentSourceId } }
129125
}
130-
131-
private buildOrganizations(
132-
row: Record<string, unknown>,
133-
): IActivityData['member']['organizations'] {
134-
const website = (row.ORG_WEBSITE as string | null)?.trim() || null
135-
const domainAliases = (row.ORG_DOMAIN_ALIASES as string | null)?.trim() || null
136-
137-
if (!website && !domainAliases) {
138-
return undefined
139-
}
140-
141-
const identities: IOrganizationIdentity[] = []
142-
143-
if (website) {
144-
identities.push({
145-
platform: PlatformType.TNC,
146-
value: website,
147-
type: OrganizationIdentityType.PRIMARY_DOMAIN,
148-
verified: true,
149-
})
150-
}
151-
152-
if (domainAliases) {
153-
for (const alias of domainAliases.split(',')) {
154-
const trimmed = alias.trim()
155-
if (trimmed) {
156-
identities.push({
157-
platform: PlatformType.TNC,
158-
value: trimmed,
159-
type: OrganizationIdentityType.ALTERNATIVE_DOMAIN,
160-
verified: true,
161-
})
162-
}
163-
}
164-
}
165-
166-
return [
167-
{
168-
displayName: (row.ORGANIZATION_NAME as string | null)?.trim() || website,
169-
source: OrganizationSource.TNC,
170-
identities,
171-
logo: (row.LOGO_URL as string | null)?.trim() || undefined,
172-
size: (row.ORGANIZATION_SIZE as string | null)?.trim() || undefined,
173-
industry: (row.ORGANIZATION_INDUSTRY as string | null)?.trim() || undefined,
174-
},
175-
]
176-
}
177126
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import {
2+
IActivityData,
3+
IOrganizationIdentity,
4+
OrganizationIdentityType,
5+
OrganizationSource,
6+
PlatformType,
7+
} from '@crowd/types'
8+
9+
import { TransformerBase } from '../../core/transformerBase'
10+
11+
export abstract class TncTransformerBase extends TransformerBase {
12+
readonly platform = PlatformType.TNC
13+
14+
protected buildOrganizations(
15+
row: Record<string, unknown>,
16+
): IActivityData['member']['organizations'] {
17+
const website = (row.ORG_WEBSITE as string | null)?.trim() || null
18+
const domainAliases = (row.ORG_DOMAIN_ALIASES as string | null)?.trim() || null
19+
20+
if (!website && !domainAliases) {
21+
return undefined
22+
}
23+
24+
const identities: IOrganizationIdentity[] = []
25+
26+
if (website) {
27+
identities.push({
28+
platform: PlatformType.TNC,
29+
value: website,
30+
type: OrganizationIdentityType.PRIMARY_DOMAIN,
31+
verified: true,
32+
})
33+
}
34+
35+
if (domainAliases) {
36+
for (const alias of domainAliases.split(',')) {
37+
const trimmed = alias.trim()
38+
if (trimmed) {
39+
identities.push({
40+
platform: PlatformType.TNC,
41+
value: trimmed,
42+
type: OrganizationIdentityType.ALTERNATIVE_DOMAIN,
43+
verified: true,
44+
})
45+
}
46+
}
47+
}
48+
49+
return [
50+
{
51+
displayName: (row.ORGANIZATION_NAME as string | null)?.trim() || website,
52+
source: OrganizationSource.TNC,
53+
identities,
54+
logo: (row.LOGO_URL as string | null)?.trim() || undefined,
55+
size: (row.ORGANIZATION_SIZE as string | null)?.trim() || undefined,
56+
industry: (row.ORGANIZATION_INDUSTRY as string | null)?.trim() || undefined,
57+
},
58+
]
59+
}
60+
}

0 commit comments

Comments
 (0)