Inventory spaces (#2715)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-03-06 21:44:37 +06:00 committed by GitHub
parent ca002b4a41
commit c6dd5a6619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<void> {
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<void> {},
async upgrade (client: MigrationUpgradeClient): Promise<void> {}
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System)
await createSpace(tx)
}
}