Skip to content

Commit 5a4689b

Browse files
authored
fix: moving insightsProjects organization on merge (#3862)
1 parent c39270f commit 5a4689b

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

services/apps/entity_merging_worker/src/activities/organizations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { WorkflowIdConflictPolicy, WorkflowIdReusePolicy } from '@temporalio/wor
22

33
import { DEFAULT_TENANT_ID } from '@crowd/common'
44
import { moveActivityRelationsToAnotherOrganization } from '@crowd/data-access-layer/src/activityRelations'
5+
import { moveInsightsProjectsToAnotherOrganization } from '@crowd/data-access-layer/src/collections'
56
import {
67
deleteOrganizationById,
78
deleteOrganizationSegments,
@@ -35,6 +36,7 @@ export async function finishOrganizationMergingUpdateActivities(
3536
): Promise<void> {
3637
const qx = pgpQx(svc.postgres.writer.connection())
3738
await moveActivityRelationsToAnotherOrganization(qx, secondaryId, primaryId)
39+
await moveInsightsProjectsToAnotherOrganization(qx, secondaryId, primaryId)
3840
}
3941

4042
export async function recalculateActivityAffiliationsOfOrganizationAsync(

services/libs/data-access-layer/src/collections/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,23 @@ function prepareProject(project: Partial<ICreateInsightsProject>) {
344344
return toUpdate
345345
}
346346

347+
export async function moveInsightsProjectsToAnotherOrganization(
348+
qx: QueryExecutor,
349+
fromId: string,
350+
toId: string,
351+
) {
352+
return qx.result(
353+
`
354+
UPDATE "insightsProjects"
355+
SET "organizationId" = $(toId),
356+
"updatedAt" = now()
357+
WHERE "organizationId" = $(fromId)
358+
AND "deletedAt" IS NULL
359+
`,
360+
{ fromId, toId },
361+
)
362+
}
363+
347364
export async function findBySlug(qx: QueryExecutor, slug: string) {
348365
const collections = await queryCollections(qx, {
349366
filter: {

0 commit comments

Comments
 (0)