From 67f7cddf03c51d9782a4ddd68b5bdfe28749478f Mon Sep 17 00:00:00 2001 From: Ilya Sumbatyants Date: Thu, 2 Dec 2021 16:04:32 +0700 Subject: [PATCH] Accounts listWorkspaces (#483) Signed-off-by: Ilya Sumbatyants --- dev/tool/src/index.ts | 12 +++++++++++- server/account/src/index.ts | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/dev/tool/src/index.ts b/dev/tool/src/index.ts index 4e97162747..48851ecb7e 100644 --- a/dev/tool/src/index.ts +++ b/dev/tool/src/index.ts @@ -16,7 +16,7 @@ import { program } from 'commander' import { MongoClient, Db } from 'mongodb' -import { getAccount, createAccount, assignWorkspace, createWorkspace, ACCOUNT_DB, dropWorkspace, dropAccount } from '@anticrm/account' +import { getAccount, createAccount, assignWorkspace, createWorkspace, ACCOUNT_DB, dropWorkspace, dropAccount, listWorkspaces } from '@anticrm/account' import { createContributingClient } from '@anticrm/contrib' import core, { TxOperations } from '@anticrm/core' import { encode } from 'jwt-simple' @@ -164,6 +164,16 @@ program }) }) +program + .command('list-workspaces') + .description('List workspaces') + .action(async () => { + return await withDatabase(mongodbUri, async (db) => { + const workspacesJSON = JSON.stringify(await listWorkspaces(db), null, 2) + console.info(workspacesJSON) + }) + }) + program .command('drop-account ') .description('drop account') diff --git a/server/account/src/index.ts b/server/account/src/index.ts index dc9c4482d1..f039de01d0 100644 --- a/server/account/src/index.ts +++ b/server/account/src/index.ts @@ -203,6 +203,15 @@ export async function createAccount (db: Db, email: string, password: string, fi } } +/** + * @public + */ +export async function listWorkspaces (db: Db): Promise { + return await db.collection(WORKSPACE_COLLECTION) + .find({}) + .toArray() +} + /** * @public */ @@ -299,7 +308,8 @@ export const methods = { createAccount: wrap(createAccount), createWorkspace: wrap(createWorkspace), assignWorkspace: wrap(assignWorkspace), - removeWorkspace: wrap(removeWorkspace) + removeWorkspace: wrap(removeWorkspace), + listWorkspaces: wrap(listWorkspaces) // updateAccount: wrap(updateAccount) }