diff --git a/packages/platform-rig/profiles/default/tsconfig.json b/packages/platform-rig/profiles/default/tsconfig.json index be41ac311d..2a819a7159 100644 --- a/packages/platform-rig/profiles/default/tsconfig.json +++ b/packages/platform-rig/profiles/default/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES2016", + "target": "ES2017", "module": "commonjs", "declaration": true, "strict": true, diff --git a/plugins/recruit-resources/src/components/CreateApplication.svelte b/plugins/recruit-resources/src/components/CreateApplication.svelte index 2279eddcfc..5f99e9808e 100644 --- a/plugins/recruit-resources/src/components/CreateApplication.svelte +++ b/plugins/recruit-resources/src/components/CreateApplication.svelte @@ -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') } diff --git a/server/view-resources/src/index.ts b/server/view-resources/src/index.ts index 65e7961502..8ec46e04e1 100644 --- a/server/view-resources/src/index.ts +++ b/server/view-resources/src/index.ts @@ -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 []