Merge pull request #829 from hcengineering/fix-825

Closes #825
This commit is contained in:
Andrey Sobolev 2022-01-14 17:00:08 +07:00 committed by GitHub
commit 87ca27978a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 15 deletions

View File

@ -1,9 +1,9 @@
import { Collection, DocumentUpdate, Hierarchy, MixinData, MixinUpdate, ModelDb } from '.'
import { DocumentUpdate, Hierarchy, MixinData, MixinUpdate, ModelDb } from '.'
import type { Account, AttachedData, AttachedDoc, Class, Data, Doc, Mixin, PropertyType, Ref, Space } from './classes'
import { Client } from './client'
import core from './component'
import type { DocumentQuery, FindOptions, FindResult, TxResult, WithLookup } from './storage'
import { Tx, TxFactory } from './tx'
import core from './component'
/**
* @public
@ -183,14 +183,4 @@ export class TxOperations implements Omit<Client, 'notify'> {
}
return this.removeDoc(doc._class, doc.space, doc._id)
}
add<T extends Doc, P extends AttachedDoc>(parent: T, _class: Ref<Class<P>>, obj: AttachedData<P>, objId?: Ref<P>): Promise<TxResult> {
const h = this.client.getHierarchy()
const attrs = Array.from(h.getAllAttributes(parent._class).values())
const collections = attrs.filter(a => h.isDerived(a.type._class, core.class.Collection) && h.isDerived(_class, (a.type as Collection<AttachedDoc>).of))
if (collections.length !== 1) {
throw new Error('Please use addCollection method, collection could not be detected.')
}
return this.addCollection<T, P>(_class, parent.space, parent._id, parent._class, collections[0].name, obj, objId)
}
}

View File

@ -43,7 +43,7 @@
)
function onMessage (event: CustomEvent) {
client.add(object, chunter.class.Comment, { message: event.detail })
client.addCollection(chunter.class.Comment, object.space, object._id, object._class, 'comments', { message: event.detail })
}
let viewlets: Map<ActivityKey, TxViewlet>

View File

@ -75,7 +75,7 @@
await client.createMixin<Contact, Customer>(customerInstance._id, customerInstance._class, customerInstance.space, lead.mixin.Customer, {})
}
await client.add(customerInstance, lead.class.Lead, value, leadId)
await client.addCollection(lead.class.Lead, _space, customer!, lead.mixin.Customer, 'leads', value, leadId)
dispatch('close')
}
</script>

View File

@ -82,8 +82,9 @@
await client.createMixin<Contact, Candidate>(candidateInstance._id, candidateInstance._class, candidateInstance.space, recruit.mixin.Candidate, {})
}
await client.add(candidateInstance,
await client.addCollection(
recruit.class.Applicant,
space, candidateInstance._id, recruit.mixin.Candidate, 'applications',
{
state: state._id,
doneState: null,