mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-11 09:51:53 +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
|
||||
title: 'Standard Operating Procedure Template'
|
||||
docPrefix: SOP
|
||||
category: DOC
|
||||
category: DC
|
||||
author: John Appleseed
|
||||
owner: John Appleseed
|
||||
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}`)
|
||||
}
|
||||
|
||||
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 category = header.category !== undefined ? this.controlledDocumentCategories.get(header.category) : undefined
|
||||
return {
|
||||
id,
|
||||
metaId,
|
||||
|
@ -196,7 +196,7 @@ export interface ImportControlledDocumentTemplate extends ImportDoc {
|
||||
major: number
|
||||
minor: number
|
||||
state: DocumentState
|
||||
category?: Ref<DocumentCategory>
|
||||
category: Ref<DocumentCategory>
|
||||
author?: Ref<Employee>
|
||||
owner?: Ref<Employee>
|
||||
abstract?: string
|
||||
|
@ -35,6 +35,7 @@ export type InitStep<T extends Doc> =
|
||||
| DefaultStep<T>
|
||||
| MixinStep<T, T>
|
||||
| UpdateStep<T>
|
||||
| BulkUpdateStep<T>
|
||||
| FindStep<T>
|
||||
| UploadStep
|
||||
| ImportStep
|
||||
@ -70,6 +71,15 @@ export interface UpdateStep<T extends Doc> {
|
||||
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> {
|
||||
type: 'find'
|
||||
_class: Ref<Class<T>>
|
||||
@ -120,6 +130,8 @@ export class WorkspaceInitializer {
|
||||
await this.processCreate(step, vars, defaults)
|
||||
} else if (step.type === 'update') {
|
||||
await this.processUpdate(step, vars)
|
||||
} else if (step.type === 'bulkUpdate') {
|
||||
await this.processBulkUpdate(step, vars)
|
||||
} else if (step.type === 'mixin') {
|
||||
await this.processMixin(step, vars)
|
||||
} else if (step.type === 'find') {
|
||||
@ -203,6 +215,16 @@ export class WorkspaceInitializer {
|
||||
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>(
|
||||
step: CreateStep<T>,
|
||||
vars: Record<string, any>,
|
||||
|
Loading…
Reference in New Issue
Block a user