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
24 changes: 13 additions & 11 deletions backend/src/bin/scripts/merge-organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import commandLineUsage from 'command-line-usage'

import OrganizationRepository from '@/database/repositories/organizationRepository'
import OrganizationService from '@/services/organizationService'
import { DEFAULT_TENANT_ID } from '@crowd/common'
import { getServiceLogger } from '@crowd/logging'

import SequelizeRepository from '../../database/repositories/sequelizeRepository'
Expand All @@ -17,13 +18,6 @@ const banner = fs.readFileSync(path.join(__dirname, 'banner.txt'), 'utf8')
const log = getServiceLogger()

const options = [
{
name: 'tenantId',
alias: 't',
typeLabel: '{underline tenantId}',
type: String,
description: 'The tenantId both organizations belongs to',
},
{
name: 'originalId',
alias: 'o',
Expand All @@ -38,7 +32,14 @@ const options = [
typeLabel: '{underline toMergeId}',
type: String,
description:
'The unique ID of an organization that will be merged into the first one. This one will be destroyed. You can provide multiple ids here separated by comma.',
'The unique ID of an organization that will be merged into the first one. This one will be destroyed. Pass one id per run and wait for the previous merge to finish before starting the next one.',
},
{
name: 'userId',
alias: 'u',
typeLabel: '{underline userId}',
type: String,
description: 'User ID of the user performing the merge.',
},
{
name: 'help',
Expand All @@ -65,17 +66,18 @@ const sections = [
const usage = commandLineUsage(sections)
const parameters = commandLineArgs(options)

if (parameters.help || !parameters.originalId || !parameters.toMergeId || !parameters.tenantId) {
if (parameters.help || !parameters.originalId || !parameters.toMergeId || !parameters.userId) {
console.log(usage)
} else {
setImmediate(async () => {
const tenantId = parameters.tenantId
const originalId = parameters.originalId
const toMergeIds = parameters.toMergeId.split(',')
const userId = parameters.userId

const options = await SequelizeRepository.getDefaultIRepositoryOptions()

options.currentTenant = { id: tenantId }
options.currentTenant = { id: DEFAULT_TENANT_ID }
options.currentUser = { id: userId }

const originalOrganizaton = await OrganizationRepository.findById(originalId, options)

Expand Down
Loading