2022-03-31 08:32:42 +00:00
|
|
|
//
|
2022-04-16 02:59:50 +00:00
|
|
|
// Copyright © 2022 Hardcore Engineering Inc.
|
2022-03-31 08:32:42 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
2022-04-16 02:59:50 +00:00
|
|
|
import core, { TxOperations } from '@anticrm/core'
|
|
|
|
import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model'
|
|
|
|
import { Team } from '@anticrm/tracker'
|
|
|
|
import tracker from './plugin'
|
|
|
|
|
|
|
|
async function createDefaultTeam (tx: TxOperations): Promise<void> {
|
|
|
|
const current = await tx.findOne(tracker.class.Team, {
|
|
|
|
_id: tracker.team.DefaultTeam
|
|
|
|
})
|
|
|
|
|
|
|
|
const currentDeleted = await tx.findOne(core.class.TxRemoveDoc, {
|
|
|
|
objectId: tracker.team.DefaultTeam
|
|
|
|
})
|
|
|
|
|
|
|
|
// Create new if not deleted by customers.
|
|
|
|
if (current === undefined && currentDeleted === undefined) {
|
|
|
|
await tx.createDoc<Team>(
|
|
|
|
tracker.class.Team,
|
|
|
|
core.space.Space,
|
|
|
|
{
|
|
|
|
name: 'Default',
|
|
|
|
description: 'Default team',
|
|
|
|
private: false,
|
|
|
|
members: [],
|
|
|
|
archived: false,
|
|
|
|
identifier: 'TSK',
|
|
|
|
sequence: 0
|
|
|
|
},
|
|
|
|
tracker.team.DefaultTeam
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function createDefaults (tx: TxOperations): Promise<void> {
|
|
|
|
await createDefaultTeam(tx)
|
|
|
|
}
|
2022-03-31 08:32:42 +00:00
|
|
|
|
|
|
|
export const trackerOperation: MigrateOperation = {
|
2022-04-16 02:59:50 +00:00
|
|
|
async migrate (client: MigrationClient): Promise<void> {},
|
2022-03-31 08:32:42 +00:00
|
|
|
async upgrade (client: MigrationUpgradeClient): Promise<void> {
|
2022-04-16 02:59:50 +00:00
|
|
|
const tx = new TxOperations(client, core.account.System)
|
|
|
|
await createDefaults(tx)
|
2022-03-31 08:32:42 +00:00
|
|
|
}
|
|
|
|
}
|