mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-12 10:25:51 +00:00
Support bulk update step in init scripts (for tracex needs) (#8663)
Signed-off-by: Anna Khismatullina <anna.khismatullina@gmail.com>
This commit is contained in:
parent
55543c72d3
commit
74d1dcc83d
@ -2,7 +2,7 @@
|
|||||||
class: documents:mixin:DocumentTemplate
|
class: documents:mixin:DocumentTemplate
|
||||||
title: 'Standard Operating Procedure Template'
|
title: 'Standard Operating Procedure Template'
|
||||||
docPrefix: SOP
|
docPrefix: SOP
|
||||||
category: DOC
|
category: DC
|
||||||
author: John Appleseed
|
author: John Appleseed
|
||||||
owner: John Appleseed
|
owner: John Appleseed
|
||||||
abstract: Template for Standard Operating Procedures
|
abstract: Template for Standard Operating Procedures
|
||||||
|
@ -855,8 +855,12 @@ export class HulyFormatImporter {
|
|||||||
throw new Error(`Author or owner not found: ${header.author} or ${header.owner}`)
|
throw new Error(`Author or owner not found: ${header.author} or ${header.owner}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const category = this.controlledDocumentCategories.get(header.category)
|
||||||
|
if (category === undefined) {
|
||||||
|
throw new Error(`Category not found: ${header.category}`)
|
||||||
|
}
|
||||||
|
|
||||||
const codeMatch = path.basename(docPath).match(/^\[([^\]]+)\]/)
|
const codeMatch = path.basename(docPath).match(/^\[([^\]]+)\]/)
|
||||||
const category = header.category !== undefined ? this.controlledDocumentCategories.get(header.category) : undefined
|
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
metaId,
|
metaId,
|
||||||
|
@ -196,7 +196,7 @@ export interface ImportControlledDocumentTemplate extends ImportDoc {
|
|||||||
major: number
|
major: number
|
||||||
minor: number
|
minor: number
|
||||||
state: DocumentState
|
state: DocumentState
|
||||||
category?: Ref<DocumentCategory>
|
category: Ref<DocumentCategory>
|
||||||
author?: Ref<Employee>
|
author?: Ref<Employee>
|
||||||
owner?: Ref<Employee>
|
owner?: Ref<Employee>
|
||||||
abstract?: string
|
abstract?: string
|
||||||
|
@ -35,6 +35,7 @@ export type InitStep<T extends Doc> =
|
|||||||
| DefaultStep<T>
|
| DefaultStep<T>
|
||||||
| MixinStep<T, T>
|
| MixinStep<T, T>
|
||||||
| UpdateStep<T>
|
| UpdateStep<T>
|
||||||
|
| BulkUpdateStep<T>
|
||||||
| FindStep<T>
|
| FindStep<T>
|
||||||
| UploadStep
|
| UploadStep
|
||||||
| ImportStep
|
| ImportStep
|
||||||
@ -70,6 +71,15 @@ export interface UpdateStep<T extends Doc> {
|
|||||||
data: Props<T>
|
data: Props<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BulkUpdateStep<T extends Doc> {
|
||||||
|
type: 'bulkUpdate'
|
||||||
|
_class: Ref<Class<T>>
|
||||||
|
query: Partial<T>
|
||||||
|
markdownFields?: string[]
|
||||||
|
collabFields?: string[]
|
||||||
|
data: Props<T>
|
||||||
|
}
|
||||||
|
|
||||||
export interface FindStep<T extends Doc> {
|
export interface FindStep<T extends Doc> {
|
||||||
type: 'find'
|
type: 'find'
|
||||||
_class: Ref<Class<T>>
|
_class: Ref<Class<T>>
|
||||||
@ -120,6 +130,8 @@ export class WorkspaceInitializer {
|
|||||||
await this.processCreate(step, vars, defaults)
|
await this.processCreate(step, vars, defaults)
|
||||||
} else if (step.type === 'update') {
|
} else if (step.type === 'update') {
|
||||||
await this.processUpdate(step, vars)
|
await this.processUpdate(step, vars)
|
||||||
|
} else if (step.type === 'bulkUpdate') {
|
||||||
|
await this.processBulkUpdate(step, vars)
|
||||||
} else if (step.type === 'mixin') {
|
} else if (step.type === 'mixin') {
|
||||||
await this.processMixin(step, vars)
|
await this.processMixin(step, vars)
|
||||||
} else if (step.type === 'find') {
|
} else if (step.type === 'find') {
|
||||||
@ -203,6 +215,16 @@ export class WorkspaceInitializer {
|
|||||||
await this.client.updateDoc(step._class, space, _id as Ref<Doc>, props)
|
await this.client.updateDoc(step._class, space, _id as Ref<Doc>, props)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async processBulkUpdate<T extends Doc>(step: BulkUpdateStep<T>, vars: Record<string, any>): Promise<void> {
|
||||||
|
const ops = this.client.apply()
|
||||||
|
const docs = await this.client.findAll(step._class, { ...(step.query as any) })
|
||||||
|
const data = await this.fillPropsWithMarkdown(step.data, vars, step.markdownFields)
|
||||||
|
for (const doc of docs) {
|
||||||
|
await ops.updateDoc(step._class, doc.space, doc._id, data)
|
||||||
|
}
|
||||||
|
await ops.commit()
|
||||||
|
}
|
||||||
|
|
||||||
private async processCreate<T extends Doc>(
|
private async processCreate<T extends Doc>(
|
||||||
step: CreateStep<T>,
|
step: CreateStep<T>,
|
||||||
vars: Record<string, any>,
|
vars: Record<string, any>,
|
||||||
|
Loading…
Reference in New Issue
Block a user