mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 03:14:40 +03:00
uberf-7090: request enhancements (#5695)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
8d7406cbbb
commit
c20c7cacd6
@ -16,7 +16,7 @@
|
||||
import activity from '@hcengineering/activity'
|
||||
import type { PersonAccount } from '@hcengineering/contact'
|
||||
import contact from '@hcengineering/contact'
|
||||
import { type Domain, type Ref, type Tx } from '@hcengineering/core'
|
||||
import { type Timestamp, type Domain, type Ref, type Tx } from '@hcengineering/core'
|
||||
import {
|
||||
ArrOf,
|
||||
type Builder,
|
||||
@ -59,6 +59,8 @@ export class TRequest extends TAttachedDoc implements Request {
|
||||
@ReadOnly()
|
||||
approved!: Ref<PersonAccount>[]
|
||||
|
||||
approvedDates?: Timestamp[]
|
||||
|
||||
requiredApprovesCount!: number
|
||||
|
||||
@Prop(TypeString(), request.string.Status)
|
||||
@ -66,6 +68,7 @@ export class TRequest extends TAttachedDoc implements Request {
|
||||
status!: RequestStatus
|
||||
|
||||
tx!: Tx
|
||||
rejectedTx?: Tx
|
||||
|
||||
@Prop(TypeRef(contact.class.PersonAccount), request.string.Rejected)
|
||||
@ReadOnly()
|
||||
|
@ -14,7 +14,7 @@
|
||||
//
|
||||
|
||||
import { PersonAccount } from '@hcengineering/contact'
|
||||
import type { AttachedDoc, Class, Doc, Mixin, Ref, Tx } from '@hcengineering/core'
|
||||
import type { AttachedDoc, Class, Doc, Mixin, Ref, Timestamp, Tx } from '@hcengineering/core'
|
||||
import type { Asset, IntlString, Plugin } from '@hcengineering/platform'
|
||||
import { plugin } from '@hcengineering/platform'
|
||||
import { AnyComponent } from '@hcengineering/ui'
|
||||
@ -26,10 +26,12 @@ import { ChatMessage } from '@hcengineering/chunter'
|
||||
export interface Request extends AttachedDoc {
|
||||
requested: Ref<PersonAccount>[]
|
||||
approved: Ref<PersonAccount>[]
|
||||
approvedDates?: Timestamp[]
|
||||
requiredApprovesCount: number
|
||||
rejected?: Ref<PersonAccount>
|
||||
status: RequestStatus
|
||||
tx: Tx
|
||||
rejectedTx?: Tx
|
||||
comments?: number
|
||||
}
|
||||
|
||||
|
@ -49,24 +49,52 @@ export async function OnRequest (tx: Tx, control: TriggerControl): Promise<Tx[]>
|
||||
|
||||
async function OnRequestUpdate (tx: TxCollectionCUD<Doc, Request>, control: TriggerControl): Promise<Tx[]> {
|
||||
const ctx = tx.tx as TxUpdateDoc<Request>
|
||||
if (ctx.operations.$push?.approved === undefined) return []
|
||||
const request = (await control.findAll(ctx.objectClass, { _id: ctx.objectId }))[0]
|
||||
if (request.approved.length === request.requiredApprovesCount) {
|
||||
const collectionTx = control.txFactory.createTxUpdateDoc(ctx.objectClass, ctx.objectSpace, ctx.objectId, {
|
||||
status: RequestStatus.Completed
|
||||
})
|
||||
collectionTx.space = core.space.Tx
|
||||
const resTx = control.txFactory.createTxCollectionCUD(
|
||||
const applyTxes: Tx[] = []
|
||||
|
||||
if (ctx.operations.$push?.approved !== undefined) {
|
||||
const request = (await control.findAll(ctx.objectClass, { _id: ctx.objectId }))[0]
|
||||
|
||||
if (request.approved.length === request.requiredApprovesCount) {
|
||||
const collectionTx = control.txFactory.createTxUpdateDoc(ctx.objectClass, ctx.objectSpace, ctx.objectId, {
|
||||
status: RequestStatus.Completed
|
||||
})
|
||||
collectionTx.space = core.space.Tx
|
||||
const resTx = control.txFactory.createTxCollectionCUD(
|
||||
tx.objectClass,
|
||||
tx.objectId,
|
||||
tx.objectSpace,
|
||||
'requests',
|
||||
collectionTx
|
||||
)
|
||||
resTx.space = core.space.Tx
|
||||
|
||||
applyTxes.push(resTx)
|
||||
applyTxes.push(request.tx)
|
||||
}
|
||||
|
||||
const approvedDateTx = control.txFactory.createTxCollectionCUD(
|
||||
tx.objectClass,
|
||||
tx.objectId,
|
||||
tx.objectSpace,
|
||||
'requests',
|
||||
collectionTx
|
||||
control.txFactory.createTxUpdateDoc(ctx.objectClass, ctx.objectSpace, ctx.objectId, {
|
||||
$push: { approvedDates: Date.now() }
|
||||
})
|
||||
)
|
||||
resTx.space = core.space.Tx
|
||||
|
||||
await control.apply([resTx, request.tx], true)
|
||||
applyTxes.push(approvedDateTx)
|
||||
}
|
||||
|
||||
if (ctx.operations.status === RequestStatus.Rejected) {
|
||||
const request = (await control.findAll(ctx.objectClass, { _id: ctx.objectId }))[0]
|
||||
if (request.rejectedTx != null) {
|
||||
applyTxes.push(request.rejectedTx)
|
||||
}
|
||||
}
|
||||
|
||||
if (applyTxes.length > 0) {
|
||||
await control.apply(applyTxes, true)
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user