mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-23 14:06:00 +03:00
TSK-467: Throw error when used for AttachedDoc (#2649)
Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
parent
463c0a692a
commit
a79c030597
@ -370,4 +370,27 @@ describe('memdb', () => {
|
||||
expect(attached).toBeDefined()
|
||||
expect(Hierarchy.mixinOrClass(attached as Doc)).toEqual(test.mixin.TaskMixinTodos)
|
||||
})
|
||||
|
||||
it('createDoc for AttachedDoc', async () => {
|
||||
expect.assertions(1)
|
||||
const { model } = await createModel()
|
||||
|
||||
const client = new TxOperations(model, core.account.System)
|
||||
const spaces = await client.findAll(core.class.Space, {})
|
||||
const task = await client.createDoc(test.class.Task, spaces[0]._id, {
|
||||
name: 'TSK1',
|
||||
number: 1,
|
||||
state: 0
|
||||
})
|
||||
try {
|
||||
await client.createDoc(test.class.TestMixinTodo, spaces[0]._id, {
|
||||
text: '',
|
||||
attachedTo: task,
|
||||
attachedToClass: test.mixin.TaskMixinTodos,
|
||||
collection: 'todos'
|
||||
})
|
||||
} catch (e) {
|
||||
expect(e).toEqual(new Error('createDoc cannot be used for objects inherited from AttachedDoc'))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -59,6 +59,10 @@ export class TxOperations implements Omit<Client, 'notify'> {
|
||||
modifiedOn?: Timestamp,
|
||||
modifiedBy?: Ref<Account>
|
||||
): Promise<Ref<T>> {
|
||||
const hierarchy = this.client.getHierarchy()
|
||||
if (hierarchy.isDerived(_class, core.class.AttachedDoc)) {
|
||||
throw new Error('createDoc cannot be used for objects inherited from AttachedDoc')
|
||||
}
|
||||
const tx = this.txFactory.createTxCreateDoc(_class, space, attributes, id, modifiedOn, modifiedBy)
|
||||
await this.client.tx(tx)
|
||||
return tx.objectId
|
||||
|
Loading…
Reference in New Issue
Block a user