diff --git a/backend/src/database/migrations/R__memberEnrichmentMaterializedViews.sql b/backend/src/database/migrations/R__memberEnrichmentMaterializedViews.sql index 77f11f40e9..016e0395d2 100644 --- a/backend/src/database/migrations/R__memberEnrichmentMaterializedViews.sql +++ b/backend/src/database/migrations/R__memberEnrichmentMaterializedViews.sql @@ -777,6 +777,7 @@ last_enriched_3_profiles as ( where mec."memberId" = m."memberId" and data is not null ) + and m."lastUpdatedAt" is not null order by m."lastUpdatedAt" desc limit 3 ), @@ -790,6 +791,7 @@ last_enriched_3_profiles_with_more_than_1000_activities as ( where mec."memberId" = m."memberId" and data is not null ) + and m."lastUpdatedAt" is not null order by m."lastUpdatedAt" desc limit 3 ), @@ -803,6 +805,7 @@ last_enriched_3_profiles_with_more_than_100_activities as ( where mec."memberId" = m."memberId" and data is not null ) + and m."lastUpdatedAt" is not null order by m."lastUpdatedAt" desc limit 3 ), @@ -816,6 +819,7 @@ last_enriched_3_profiles_with_more_than_10_activities as ( where mec."memberId" = m."memberId" and data is not null ) + and m."lastUpdatedAt" is not null order by m."lastUpdatedAt" desc limit 3 ), diff --git a/services/apps/premium/members_enrichment_worker/src/sources/crustdata/service.ts b/services/apps/premium/members_enrichment_worker/src/sources/crustdata/service.ts index abcb607dc5..195fe8ce82 100644 --- a/services/apps/premium/members_enrichment_worker/src/sources/crustdata/service.ts +++ b/services/apps/premium/members_enrichment_worker/src/sources/crustdata/service.ts @@ -356,8 +356,8 @@ export default class EnrichmentServiceCrustdata extends LoggerBase implements IE source: OrganizationSource.ENRICHMENT_CRUSTDATA, identities, title: workExperience.employee_title, - startDate: workExperience.start_date, - endDate: workExperience.end_date, + startDate: workExperience?.start_date ?? null, + endDate: workExperience?.end_date ?? null, organizationDescription: workExperience.employer_linkedin_description, }) } diff --git a/services/libs/data-access-layer/src/old/apps/premium/members_enrichment_worker/index.ts b/services/libs/data-access-layer/src/old/apps/premium/members_enrichment_worker/index.ts index bec43aaaf4..cc211bbd03 100644 --- a/services/libs/data-access-layer/src/old/apps/premium/members_enrichment_worker/index.ts +++ b/services/libs/data-access-layer/src/old/apps/premium/members_enrichment_worker/index.ts @@ -500,15 +500,29 @@ export async function updateMemberOrg( dateStart: toUpdate.dateStart === undefined ? toUpdate.dateStart : original.dateStart, dateEnd: toUpdate.dateEnd === undefined ? toUpdate.dateEnd : original.dateEnd, } + + let dateEndFilter = `and "dateEnd" = $(dateEnd)` + let dateStartFilter = `and "dateStart" = $(dateStart)` + + if (params.dateEnd === null) { + dateEndFilter = `and "dateEnd" is null` + delete params.dateEnd + } + + if (params.dateStart === null) { + dateStartFilter = ` and "dateStart" is null` + delete params.dateStart + } + const existing = await tx.oneOrNone( ` select 1 from "memberOrganizations" - where "memberId" = $(memberId) and - "organizationId" = $(organizationId) and - "dateStart" = $(dateStart) and - "dateEnd" = $(dateEnd) and - "deletedAt" is null - and id <> $(id) + where "memberId" = $(memberId) + and "organizationId" = $(organizationId) + ${dateStartFilter} + ${dateEndFilter} + and "deletedAt" is null + and id <> $(id) `, params, )