From c6dd5a66192808b32fff2c30a4e71a51491ec750 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Mon, 6 Mar 2023 21:44:37 +0600 Subject: [PATCH] Inventory spaces (#2715) Signed-off-by: Denis Bykhov --- models/inventory/src/migration.ts | 44 ++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/models/inventory/src/migration.ts b/models/inventory/src/migration.ts index 515ba8551b..c657e925c3 100644 --- a/models/inventory/src/migration.ts +++ b/models/inventory/src/migration.ts @@ -13,9 +13,51 @@ // limitations under the License. // +import core, { TxOperations } from '@hcengineering/core' import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@hcengineering/model' +import inventory from './plugin' + +async function createSpace (tx: TxOperations): Promise { + const categories = await tx.findOne(core.class.Space, { + _id: inventory.space.Category + }) + if (categories === undefined) { + await tx.createDoc( + core.class.Space, + core.space.Space, + { + name: 'Categories', + description: 'Categories', + private: false, + archived: false, + members: [] + }, + inventory.space.Category + ) + } + const products = await tx.findOne(core.class.Space, { + _id: inventory.space.Products + }) + if (products === undefined) { + await tx.createDoc( + core.class.Space, + core.space.Space, + { + name: 'Products', + description: 'Products', + private: false, + archived: false, + members: [] + }, + inventory.space.Products + ) + } +} export const inventoryOperation: MigrateOperation = { async migrate (client: MigrationClient): Promise {}, - async upgrade (client: MigrationUpgradeClient): Promise {} + async upgrade (client: MigrationUpgradeClient): Promise { + const tx = new TxOperations(client, core.account.System) + await createSpace(tx) + } }