mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 11:42:30 +03:00
ezqms-1121: fix deleted doc states (#6112)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
434163f00a
commit
93b798c99b
@ -22,6 +22,15 @@ export function createModel (builder: Builder): void {
|
||||
}
|
||||
})
|
||||
|
||||
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
|
||||
trigger: serverDocuments.trigger.OnDocDeleted,
|
||||
txMatch: {
|
||||
_class: core.class.TxUpdateDoc,
|
||||
objectClass: documents.class.ControlledDocument,
|
||||
'operations.state': DocumentState.Deleted
|
||||
}
|
||||
})
|
||||
|
||||
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
|
||||
trigger: serverDocuments.trigger.OnDocPlannedEffectiveDateChanged,
|
||||
txMatch: {
|
||||
|
@ -31,9 +31,11 @@ import documents, {
|
||||
calcRank,
|
||||
type DocumentTraining,
|
||||
getEffectiveDocUpdate,
|
||||
getDocumentId
|
||||
getDocumentId,
|
||||
type DocumentRequest
|
||||
} from '@hcengineering/controlled-documents'
|
||||
import training, { type TrainingRequest, TrainingState } from '@hcengineering/training'
|
||||
import { RequestStatus } from '@hcengineering/request'
|
||||
|
||||
/**
|
||||
* @public
|
||||
@ -351,6 +353,26 @@ export async function OnDocHasBecomeEffective (
|
||||
]
|
||||
}
|
||||
|
||||
export async function OnDocDeleted (tx: TxUpdateDoc<ControlledDocument>, control: TriggerControl): Promise<Tx[]> {
|
||||
const requests = await control.findAll(documents.class.DocumentRequest, {
|
||||
attachedTo: tx.objectId,
|
||||
status: RequestStatus.Active
|
||||
})
|
||||
const cancelTxes = requests.map((request) =>
|
||||
control.txFactory.createTxUpdateDoc<DocumentRequest>(request._class, request.space, request._id, {
|
||||
status: RequestStatus.Cancelled
|
||||
})
|
||||
)
|
||||
await control.apply([
|
||||
...cancelTxes,
|
||||
control.txFactory.createTxUpdateDoc<ControlledDocument>(tx.objectClass, tx.objectSpace, tx.objectId, {
|
||||
controlledState: undefined
|
||||
})
|
||||
])
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
export async function OnDocPlannedEffectiveDateChanged (
|
||||
tx: TxUpdateDoc<ControlledDocument>,
|
||||
control: TriggerControl
|
||||
@ -446,6 +468,7 @@ export async function documentTextPresenter (doc: ControlledDocument): Promise<s
|
||||
export default async () => ({
|
||||
trigger: {
|
||||
OnCollaborativeSectionDeleted,
|
||||
OnDocDeleted,
|
||||
OnDocPlannedEffectiveDateChanged,
|
||||
OnDocApprovalRequestApproved,
|
||||
OnDocHasBecomeEffective,
|
||||
|
@ -19,6 +19,7 @@ export const serverDocumentsId = 'server-documents' as Plugin
|
||||
export default plugin(serverDocumentsId, {
|
||||
trigger: {
|
||||
OnCollaborativeSectionDeleted: '' as Resource<TriggerFunc>,
|
||||
OnDocDeleted: '' as Resource<TriggerFunc>,
|
||||
OnDocPlannedEffectiveDateChanged: '' as Resource<TriggerFunc>,
|
||||
OnDocApprovalRequestApproved: '' as Resource<TriggerFunc>,
|
||||
OnDocHasBecomeEffective: '' as Resource<TriggerFunc>,
|
||||
|
Loading…
Reference in New Issue
Block a user