Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-09-09 14:42:59 +06:00 committed by GitHub
parent 28be42ee92
commit c04b2d47b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,13 +13,14 @@
// limitations under the License.
//
import core, { TxOperations } from '@hcengineering/core'
import core, { DOMAIN_STATUS, DOMAIN_TX, Status, TxCUD, TxOperations, TxProcessor } from '@hcengineering/core'
import { MigrateOperation, MigrationClient, MigrationUpgradeClient, createOrUpdate } from '@hcengineering/model'
import { DOMAIN_TASK } from '@hcengineering/model-task'
import tags from '@hcengineering/tags'
import { Project, TimeReportDayType, createStatuses } from '@hcengineering/tracker'
import { DOMAIN_TRACKER } from '.'
import tracker from './plugin'
import { DOMAIN_SPACE } from '@hcengineering/model-core'
async function createDefaultProject (tx: TxOperations): Promise<void> {
const current = await tx.findOne(tracker.class.Project, {
@ -89,9 +90,32 @@ async function moveIssues (client: MigrationClient): Promise<void> {
}
}
async function fixProjectDefaultStatuses (client: MigrationClient): Promise<void> {
const projects = await client.find<Project>(DOMAIN_SPACE, { _class: tracker.class.Project })
for (const project of projects) {
const state = await client.find(DOMAIN_STATUS, { _id: project.defaultIssueStatus })
if (state.length === 0) {
const oldStateTxes = await client.find<TxCUD<Status>>(DOMAIN_TX, { objectId: project.defaultIssueStatus })
const oldState = TxProcessor.buildDoc2Doc<Status>(oldStateTxes)
if (oldState !== undefined) {
const newState = await client.find<Status>(DOMAIN_STATUS, {
name: oldState.name.trim(),
ofAttribute: tracker.attribute.IssueStatus
})
if (newState.length > 0) {
await client.update(DOMAIN_SPACE, { _id: project._id }, { defaultIssueStatus: newState[0]._id })
}
} else {
await client.update(DOMAIN_SPACE, { _id: project._id }, { defaultIssueStatus: project.states[0] })
}
}
}
}
export const trackerOperation: MigrateOperation = {
async migrate (client: MigrationClient): Promise<void> {
await moveIssues(client)
await fixProjectDefaultStatuses(client)
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System)