mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 11:50:56 +00:00
DocWithState
trigger
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
3d833008f5
commit
4f147640c5
@ -1,6 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2016",
|
||||
"target": "ES2017",
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
|
@ -44,26 +44,26 @@
|
||||
const client = getClient()
|
||||
|
||||
async function createApplication() {
|
||||
const state = await client.findOne(core.class.State, { space: _space })
|
||||
if (state === undefined) {
|
||||
throw new Error('create application: state not found')
|
||||
}
|
||||
// const state = await client.findOne(core.class.State, { space: _space })
|
||||
// if (state === undefined) {
|
||||
// throw new Error('create application: state not found')
|
||||
// }
|
||||
const id = await client.createDoc(recruit.class.Applicant, _space, {
|
||||
candidate,
|
||||
state: state._id
|
||||
// state: state._id
|
||||
})
|
||||
|
||||
const kanban = await client.findOne(view.class.Kanban, { attachedTo: _space })
|
||||
// const kanban = await client.findOne(view.class.Kanban, { attachedTo: _space })
|
||||
|
||||
if (kanban === undefined) {
|
||||
throw new Error('kanban object not found')
|
||||
}
|
||||
// if (kanban === undefined) {
|
||||
// throw new Error('kanban object not found')
|
||||
// }
|
||||
|
||||
await client.updateDoc(view.class.Kanban, _space, kanban._id, {
|
||||
$push: {
|
||||
order: id
|
||||
}
|
||||
})
|
||||
// await client.updateDoc(view.class.Kanban, _space, kanban._id, {
|
||||
// $push: {
|
||||
// order: id
|
||||
// }
|
||||
// })
|
||||
dispatch('close')
|
||||
}
|
||||
|
||||
|
@ -14,10 +14,11 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import type { Tx, TxFactory, Doc, TxCreateDoc, DocWithState } from '@anticrm/core'
|
||||
import type { Tx, TxFactory, Doc, TxCreateDoc, DocWithState, State, TxRemoveDoc } from '@anticrm/core'
|
||||
import type { FindAll } from '@anticrm/server-core'
|
||||
|
||||
import core, { Hierarchy } from '@anticrm/core'
|
||||
import view, { Kanban } from '@anticrm/view'
|
||||
|
||||
/**
|
||||
* @public
|
||||
@ -26,7 +27,29 @@ export async function OnDocWithState (tx: Tx, txFactory: TxFactory, findAll: Fin
|
||||
if (tx._class === core.class.TxCreateDoc) {
|
||||
const createTx = tx as TxCreateDoc<DocWithState>
|
||||
if (hierarchy.isDerived(createTx.objectClass, core.class.DocWithState)) {
|
||||
console.log('OnDocWithState derived here')
|
||||
const state = (await (findAll as FindAll<State>)(core.class.State, { space: createTx.objectSpace }))[0] // TODO: make FindAll generic
|
||||
if (state === undefined) {
|
||||
throw new Error('OnDocWithState: state not found')
|
||||
}
|
||||
const kanban = (await (findAll as FindAll<Kanban>)(view.class.Kanban, { attachedTo: createTx.objectSpace }))[0]
|
||||
if (kanban === undefined) {
|
||||
throw new Error('OnDocWithState: kanban not found')
|
||||
}
|
||||
return [
|
||||
txFactory.createTxUpdateDoc(createTx.objectClass, createTx.objectSpace, createTx.objectId, { state: state._id }),
|
||||
txFactory.createTxUpdateDoc(view.class.Kanban, createTx.objectSpace, kanban._id, { $push: { order: createTx.objectId } })
|
||||
]
|
||||
}
|
||||
} else if (tx._class === core.class.TxRemoveDoc) {
|
||||
const removeTx = tx as TxRemoveDoc<DocWithState>
|
||||
if (hierarchy.isDerived(removeTx.objectClass, core.class.DocWithState)) {
|
||||
const kanban = (await (findAll as FindAll<Kanban>)(view.class.Kanban, { attachedTo: removeTx.objectSpace }))[0]
|
||||
if (kanban === undefined) {
|
||||
throw new Error('OnDocWithState: kanban not found')
|
||||
}
|
||||
return [
|
||||
txFactory.createTxUpdateDoc(view.class.Kanban, removeTx.objectSpace, kanban._id, { $pull: { order: removeTx.objectId } })
|
||||
]
|
||||
}
|
||||
}
|
||||
return []
|
||||
|
Loading…
Reference in New Issue
Block a user