mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 21:50:34 +03:00
drop commands in dev/tool
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
ef53d5393e
commit
ad714b4653
@ -16,7 +16,7 @@
|
||||
|
||||
import { program } from 'commander'
|
||||
import { MongoClient, Db } from 'mongodb'
|
||||
import { getAccount, createAccount, assignWorkspace, createWorkspace, ACCOUNT_DB } from '@anticrm/account'
|
||||
import { getAccount, createAccount, assignWorkspace, createWorkspace, ACCOUNT_DB, dropWorkspace, dropAccount } from '@anticrm/account'
|
||||
import { createContributingClient } from '@anticrm/contrib'
|
||||
import core, { TxOperations } from '@anticrm/core'
|
||||
import { encode } from 'jwt-simple'
|
||||
@ -148,4 +148,22 @@ program
|
||||
})
|
||||
})
|
||||
|
||||
program
|
||||
.command('drop-workspace <name>')
|
||||
.description('drop workspace')
|
||||
.action(async (workspace, cmd) => {
|
||||
return await withDatabase(mongodbUri, async (db) => {
|
||||
await dropWorkspace(db, workspace)
|
||||
})
|
||||
})
|
||||
|
||||
program
|
||||
.command('drop-account <name>')
|
||||
.description('drop account')
|
||||
.action(async (email, cmd) => {
|
||||
return await withDatabase(mongodbUri, async (db) => {
|
||||
await dropAccount(db, email)
|
||||
})
|
||||
})
|
||||
|
||||
program.parse(process.argv)
|
||||
|
@ -250,6 +250,30 @@ export async function removeWorkspace (db: Db, email: string, workspace: string)
|
||||
await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: accountId }, { $pull: { workspaces: workspaceId } })
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function dropWorkspace (db: Db, workspace: string): Promise<void> {
|
||||
const ws = await getWorkspace(db, workspace)
|
||||
if (ws === null) {
|
||||
throw new PlatformError(new Status(Severity.ERROR, accountPlugin.status.WorkspaceNotFound, { workspace }))
|
||||
}
|
||||
await db.collection(WORKSPACE_COLLECTION).deleteOne({ _id: ws._id })
|
||||
await db.collection<Account>(ACCOUNT_COLLECTION).updateMany({ _id: { $in: ws.accounts } }, { $pull: { workspaces: ws._id } })
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function dropAccount (db: Db, email: string): Promise<void> {
|
||||
const account = await getAccount(db, email)
|
||||
if (account === null) {
|
||||
throw new PlatformError(new Status(Severity.ERROR, accountPlugin.status.AccountNotFound, { account: email }))
|
||||
}
|
||||
await db.collection(ACCOUNT_COLLECTION).deleteOne({ _id: account._id })
|
||||
await db.collection<Workspace>(WORKSPACE_COLLECTION).updateMany({ _id: { $in: account.workspaces } }, { $pull: { accounts: account._id } })
|
||||
}
|
||||
|
||||
function wrap (f: (db: Db, ...args: any[]) => Promise<any>) {
|
||||
return async function (db: Db, request: Request<any[]>): Promise<Response<any>> {
|
||||
return await f(db, ...request.params)
|
||||
|
Loading…
Reference in New Issue
Block a user