Skip to content

Commit

Permalink
Fix organization OpenSearch translator (#1987)
Browse files Browse the repository at this point in the history
  • Loading branch information
skwowet authored Dec 21, 2023
1 parent 5a99916 commit db3827f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 5 deletions.
33 changes: 30 additions & 3 deletions services/libs/opensearch/src/models/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class OrganizationsOpensearch extends OpensearchModelBase {
},
address: {
type: OpensearchFieldType.OBJECT,
preventNestedFieldTranslation: true,
},
logo: {
type: OpensearchFieldType.STRING,
Expand All @@ -41,8 +42,16 @@ export class OrganizationsOpensearch extends OpensearchModelBase {
tags: {
type: OpensearchFieldType.STRING_ARR,
},
naics: {
type: OpensearchFieldType.OBJECT,
preventNestedFieldTranslation: true,
},
ticker: {
type: OpensearchFieldType.STRING,
},
employeeCountByCountry: {
type: OpensearchFieldType.OBJECT,
preventNestedFieldTranslation: true,
},
employees: {
type: OpensearchFieldType.INT,
Expand Down Expand Up @@ -128,17 +137,24 @@ export class OrganizationsOpensearch extends OpensearchModelBase {
fromOpensearch: 'nested_identities',
},
},
weakIdentities: {
type: OpensearchFieldType.NESTED,
customTranslation: {
toOpensearch: 'nested_weakIdentities.string_name',
fromOpensearch: 'nested_weakIdentities',
},
},
isTeamOrganization: {
type: OpensearchFieldType.BOOL,
},
manuallyCreated: {
type: OpensearchFieldType.BOOL,
},
immediateParent: {
type: OpensearchFieldType.STRING_ARR,
type: OpensearchFieldType.STRING,
},
ultimateParent: {
type: OpensearchFieldType.STRING_ARR,
type: OpensearchFieldType.STRING,
},
affiliatedProfiles: {
type: OpensearchFieldType.STRING_ARR,
Expand All @@ -154,12 +170,15 @@ export class OrganizationsOpensearch extends OpensearchModelBase {
},
averageEmployeeTenure: {
type: OpensearchFieldType.FLOAT,
preventNestedFieldTranslation: true,
},
averageTenureByLevel: {
type: OpensearchFieldType.OBJECT,
preventNestedFieldTranslation: true,
},
averageTenureByRole: {
type: OpensearchFieldType.OBJECT,
preventNestedFieldTranslation: true,
},
directSubsidiaries: {
type: OpensearchFieldType.STRING_ARR,
Expand All @@ -170,31 +189,39 @@ export class OrganizationsOpensearch extends OpensearchModelBase {
},
employeeCountByMonth: {
type: OpensearchFieldType.OBJECT,
preventNestedFieldTranslation: true,
},
employeeGrowthRate: {
type: OpensearchFieldType.OBJECT,
preventNestedFieldTranslation: true,
},
employeeCountByMonthByLevel: {
type: OpensearchFieldType.OBJECT,
preventNestedFieldTranslation: true,
},
employeeCountByMonthByRole: {
type: OpensearchFieldType.OBJECT,
preventNestedFieldTranslation: true,
},
gicsSector: {
type: OpensearchFieldType.STRING_ARR,
type: OpensearchFieldType.STRING,
},
grossAdditionsByMonth: {
type: OpensearchFieldType.OBJECT,
preventNestedFieldTranslation: true,
},
grossDeparturesByMonth: {
type: OpensearchFieldType.OBJECT,
preventNestedFieldTranslation: true,
},
employeeChurnRate12Month: {
type: OpensearchFieldType.FLOAT,
},
employeeGrowthRate12Month: {
type: OpensearchFieldType.FLOAT,
},
manuallyChangedFields: {
type: OpensearchFieldType.STRING_ARR,
},
}
}
4 changes: 4 additions & 0 deletions services/libs/opensearch/src/organizationTranslator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default class OrganizationTranslator extends FieldTranslator {
return acc
}, {})

// weakIdentities
this.translations.integrationId = 'uuid_integrationId'
this.translations.sourceId = 'uuid_sourceId'

// identities
this.translations.platform = 'string_platform'
this.translations.name = 'string_name'
Expand Down
2 changes: 2 additions & 0 deletions services/libs/opensearch/src/repo/organization.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export interface IDbOrganizationSyncData {
employeeChurnRate12Month: number | null
employeeGrowthRate12Month: number | null
tags: string[] | null
ticker: string | null
manuallyChangedFields: string[] | null

// aggregate data
joinedAt: string
Expand Down
5 changes: 3 additions & 2 deletions services/libs/opensearch/src/repo/organization.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ export class OrganizationRepository extends RepositoryBase<OrganizationRepositor
o."grossDeparturesByMonth",
o."ultimateParent",
o."immediateParent",
o."weakIdentities",
o."manuallyChangedFields",
nullif (o."employeeChurnRate" -> '12_month', 'null')::decimal AS "employeeChurnRate12Month",
nullif (o."employeeGrowthRate" -> '12_month', 'null')::decimal AS "employeeGrowthRate12Month",
o.tags,
Expand All @@ -254,8 +256,7 @@ export class OrganizationRepository extends RepositoryBase<OrganizationRepositor
md."memberIds",
coalesce(i.identities, '[]'::jsonb) as "identities",
coalesce(tmd.to_merge_ids, array []::text[]) as "toMergeIds",
coalesce(nmd.no_merge_ids, array []::text[]) as "noMergeIds",
o."weakIdentities"
coalesce(nmd.no_merge_ids, array []::text[]) as "noMergeIds"
FROM organizations o
LEFT JOIN member_data md ON o.id = md."organizationId"
LEFT JOIN identities i ON o.id = i."organizationId"
Expand Down
2 changes: 2 additions & 0 deletions services/libs/opensearch/src/service/init.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export class InitService {
employeeChurnRate12Month: 0.12,
employeeGrowthRate12Month: 0.12,
attributes: {},
ticker: 'FAKE',
manuallyChangedFields: [],
createdAt: new Date().toISOString(),
description: 'Fake organization',
displayName: 'Fake organization',
Expand Down
18 changes: 18 additions & 0 deletions services/libs/opensearch/src/service/organization.sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,24 @@ export class OrganizationSyncService {
p.string_gicsSector = data.gicsSector
p.obj_grossAdditionsByMonth = data.grossAdditionsByMonth
p.obj_grossDeparturesByMonth = data.grossDeparturesByMonth
p.obj_naics = data.naics
p.string_ticker = data.ticker
p.string_arr_tags = data.tags
p.string_arr_manuallyChangedFields = data.manuallyChangedFields

// weak identities
const p_weakIdentities = []
for (const identity of data.weakIdentities) {
p_weakIdentities.push({
uuid_organizationId: identity.organizationId,
uuid_integrationId: identity.integrationId,
string_platform: identity.platform,
string_name: identity.name,
uuid_sourceId: identity.sourceId,
string_url: identity.url,
})
}
p.nested_weakIdentities = p_weakIdentities

// identities
const p_identities = []
Expand Down

0 comments on commit db3827f

Please sign in to comment.