From 601b00dcd51bdb3dccf03ee53c00ca3f6e1f1004 Mon Sep 17 00:00:00 2001 From: Yeganathan S Date: Fri, 6 Oct 2023 01:09:55 +0530 Subject: [PATCH] Auto merge organization on website conflict during enrichment --- .../enrichment/organizationEnrichmentService.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/src/services/premium/enrichment/organizationEnrichmentService.ts b/backend/src/services/premium/enrichment/organizationEnrichmentService.ts index 77ee7bee62..985c4454b7 100644 --- a/backend/src/services/premium/enrichment/organizationEnrichmentService.ts +++ b/backend/src/services/premium/enrichment/organizationEnrichmentService.ts @@ -17,6 +17,7 @@ import { IServiceOptions } from '../../IServiceOptions' import { EnrichmentParams, IEnrichmentResponse } from './types/organizationEnrichmentTypes' import { getSearchSyncWorkerEmitter } from '@/serverless/utils/serviceSQS' import SequelizeRepository from '@/database/repositories/sequelizeRepository' +import OrganizationService from '@/services/organizationService' export default class OrganizationEnrichmentService extends LoggerBase { tenantId: string @@ -163,6 +164,16 @@ export default class OrganizationEnrichmentService extends LoggerBase { } delete org.identities + + // Check for an organization with the same website exists + const existingOrg = await OrganizationRepository.findByDomain(org.website, this.options) + const orgService = new OrganizationService(this.options) + + if (existingOrg) { + await orgService.merge(existingOrg.id, org.id) + // remove the merged org from the list + orgs = orgs.filter((o) => o.id !== org.id) + } } // TODO: Update cache