mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-14 11:24:06 +00:00
Fix mixins for calendar event (#8392)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
a34c945597
commit
93060578fe
@ -29,6 +29,7 @@ import core, {
|
|||||||
Tx,
|
Tx,
|
||||||
TxCreateDoc,
|
TxCreateDoc,
|
||||||
TxCUD,
|
TxCUD,
|
||||||
|
TxMixin,
|
||||||
TxProcessor,
|
TxProcessor,
|
||||||
TxRemoveDoc,
|
TxRemoveDoc,
|
||||||
TxUpdateDoc
|
TxUpdateDoc
|
||||||
@ -145,12 +146,36 @@ async function OnEvent (txes: Tx[], control: TriggerControl): Promise<Tx[]> {
|
|||||||
result.push(...(await onEventUpdate(ctx as TxUpdateDoc<Event>, control)))
|
result.push(...(await onEventUpdate(ctx as TxUpdateDoc<Event>, control)))
|
||||||
} else if (ctx._class === core.class.TxRemoveDoc) {
|
} else if (ctx._class === core.class.TxRemoveDoc) {
|
||||||
result.push(...(await onRemoveEvent(ctx as TxRemoveDoc<Event>, control)))
|
result.push(...(await onRemoveEvent(ctx as TxRemoveDoc<Event>, control)))
|
||||||
|
} else if (ctx._class === core.class.TxMixin) {
|
||||||
|
result.push(...(await onEventMixin(ctx as TxMixin<Event, Event>, control)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function onEventMixin (ctx: TxMixin<Event, Event>, control: TriggerControl): Promise<Tx[]> {
|
||||||
|
const ops = ctx.attributes
|
||||||
|
const event = (await control.findAll(control.ctx, calendar.class.Event, { _id: ctx.objectId }, { limit: 1 }))[0]
|
||||||
|
if (event === undefined) return []
|
||||||
|
if (event.access !== 'owner') return []
|
||||||
|
const events = await control.findAll(control.ctx, calendar.class.Event, { eventId: event.eventId })
|
||||||
|
const res: Tx[] = []
|
||||||
|
for (const ev of events) {
|
||||||
|
if (ev._id === event._id) continue
|
||||||
|
const innerTx = control.txFactory.createTxMixin(ev._id, ev._class, ev.space, ctx.mixin, { ...ops })
|
||||||
|
const outerTx = control.txFactory.createTxCollectionCUD(
|
||||||
|
ev.attachedToClass,
|
||||||
|
ev.attachedTo,
|
||||||
|
ev.space,
|
||||||
|
ev.collection,
|
||||||
|
innerTx
|
||||||
|
)
|
||||||
|
res.push(outerTx)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
async function onEventUpdate (ctx: TxUpdateDoc<Event>, control: TriggerControl): Promise<Tx[]> {
|
async function onEventUpdate (ctx: TxUpdateDoc<Event>, control: TriggerControl): Promise<Tx[]> {
|
||||||
const ops = ctx.operations
|
const ops = ctx.operations
|
||||||
const { visibility, ...otherOps } = ops
|
const { visibility, ...otherOps } = ops
|
||||||
|
Loading…
Reference in New Issue
Block a user