Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions services/apps/members_enrichment_worker/src/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import {
updateMemberUsingSquashedPayload,
} from './activities/enrichment'
import { refreshToken } from './activities/lf-auth0/authenticateLFAuth0'
import {
getIdentitiesExistInOtherMembers,
mergeMembers,
updateMemberWithEnrichmentData,
} from './activities/lf-auth0/enrichLFAuth0'
import { getEnrichmentLFAuth0 } from './activities/lf-auth0/getEnrichmentLFAuth0'
import { getLFIDEnrichableMembers } from './activities/lf-auth0/getLFIDEnrichableMembers'
import {
Expand All @@ -39,9 +34,12 @@ import {
} from './activities/llm'
import {
getEnrichableMembers,
getIdentitiesExistInOtherMembers,
getMemberById,
mergeMembers,
syncMembersToOpensearch,
syncOrganizationsToOpensearch,
updateMemberWithEnrichmentData,
} from './activities/member'

export {
Expand Down

This file was deleted.

84 changes: 82 additions & 2 deletions services/apps/members_enrichment_worker/src/activities/member.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { MemberField, findMemberById, pgpQx } from '@crowd/data-access-layer'
import { fetchMembersForEnrichment } from '@crowd/data-access-layer/src/old/apps/members_enrichment_worker'
import {
MemberField,
PgPromiseQueryExecutor,
createMemberIdentity,
findMemberById,
pgpQx,
} from '@crowd/data-access-layer'
import {
fetchMembersForEnrichment,
getIdentitiesExistInOtherMembers as getIdentitiesExistInOthers,
updateMemberAttributes,
} from '@crowd/data-access-layer/src/old/apps/members_enrichment_worker'
import { MemberSyncService, OrganizationSyncService } from '@crowd/opensearch'
import {
IAttributes,
IEnrichableMember,
IEnrichmentSourceQueryInput,
IMemberIdentity,
MemberEnrichmentSource,
} from '@crowd/types'

Expand Down Expand Up @@ -60,3 +72,71 @@
export async function syncOrganizationsToOpensearch(input: string[]): Promise<void> {
await organizationSyncService.syncOrganizations(input)
}

export async function getIdentitiesExistInOtherMembers(
excludeMemberId: string,
identities: IMemberIdentity[],
): Promise<IMemberIdentity[]> {
let rows: IMemberIdentity[] = []

try {

Check failure on line 82 in services/apps/members_enrichment_worker/src/activities/member.ts

View workflow job for this annotation

GitHub Actions / lint-format-services

Unnecessary try/catch wrapper
const db = svc.postgres.reader
rows = await getIdentitiesExistInOthers(db, excludeMemberId, identities)
} catch (err) {
throw err
}
Comment thread
skwowet marked this conversation as resolved.

return rows
}

export async function updateMemberWithEnrichmentData(
memberId: string,
identities: IMemberIdentity[],
attributes?: IAttributes,
): Promise<void> {
try {

Check failure on line 97 in services/apps/members_enrichment_worker/src/activities/member.ts

View workflow job for this annotation

GitHub Actions / lint-format-services

Unnecessary try/catch wrapper
await svc.postgres.writer.connection().tx(async (tx) => {
for (const identity of identities) {
await createMemberIdentity(new PgPromiseQueryExecutor(tx), {
memberId,
platform: identity.platform,
value: identity.value,
type: identity.type,
verified: identity.verified || false,
source: 'enrichment',
})
}
if (attributes) {
await updateMemberAttributes(tx, memberId, attributes)
}
})
} catch (err) {
throw err
}
Comment thread
skwowet marked this conversation as resolved.
}

export async function mergeMembers(
primaryMemberId: string,
secondaryMemberId: string,
): Promise<void> {
const res = await fetch(
`${process.env['CROWD_API_SERVICE_URL']}/member/${primaryMemberId}/merge`,
{
method: 'PUT',
headers: {
Authorization: `Bearer ${process.env['CROWD_API_SERVICE_USER_TOKEN']}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
memberToMerge: secondaryMemberId,
}),
},
)

if (res.status !== 200) {
const body = await res.text()
throw new Error(
`Failed to merge member ${primaryMemberId} with ${secondaryMemberId}! Status: ${res.status}, Response: ${body}`,
)
Comment thread
skwowet marked this conversation as resolved.
}
}
Loading