Skip to content

Commit 601b00d

Browse files
committed
Auto merge organization on website conflict during enrichment
1 parent b0ec386 commit 601b00d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

backend/src/services/premium/enrichment/organizationEnrichmentService.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { IServiceOptions } from '../../IServiceOptions'
1717
import { EnrichmentParams, IEnrichmentResponse } from './types/organizationEnrichmentTypes'
1818
import { getSearchSyncWorkerEmitter } from '@/serverless/utils/serviceSQS'
1919
import SequelizeRepository from '@/database/repositories/sequelizeRepository'
20+
import OrganizationService from '@/services/organizationService'
2021

2122
export default class OrganizationEnrichmentService extends LoggerBase {
2223
tenantId: string
@@ -163,6 +164,16 @@ export default class OrganizationEnrichmentService extends LoggerBase {
163164
}
164165

165166
delete org.identities
167+
168+
// Check for an organization with the same website exists
169+
const existingOrg = await OrganizationRepository.findByDomain(org.website, this.options)
170+
const orgService = new OrganizationService(this.options)
171+
172+
if (existingOrg) {
173+
await orgService.merge(existingOrg.id, org.id)
174+
// remove the merged org from the list
175+
orgs = orgs.filter((o) => o.id !== org.id)
176+
}
166177
}
167178

168179
// TODO: Update cache

0 commit comments

Comments
 (0)