Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto merge organization on website conflict during enrichment #1633

Merged
merged 1 commit into from
Oct 5, 2023
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