Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down