From 419256be6b4d43cc10945105d38e3a08d0414063 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Fri, 14 Jan 2022 16:43:58 +0700 Subject: [PATCH] Closes #825 Closes #825 Signed-off-by: Andrey Sobolev --- packages/core/src/operations.ts | 14 ++------------ .../src/components/Activity.svelte | 2 +- .../src/components/CreateLead.svelte | 2 +- .../src/components/CreateApplication.svelte | 3 ++- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/core/src/operations.ts b/packages/core/src/operations.ts index 8d07c621bb..be6fd40038 100644 --- a/packages/core/src/operations.ts +++ b/packages/core/src/operations.ts @@ -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 { } return this.removeDoc(doc._class, doc.space, doc._id) } - - add(parent: T, _class: Ref>, obj: AttachedData

, objId?: Ref

): Promise { - 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).of)) - if (collections.length !== 1) { - throw new Error('Please use addCollection method, collection could not be detected.') - } - return this.addCollection(_class, parent.space, parent._id, parent._class, collections[0].name, obj, objId) - } } diff --git a/plugins/activity-resources/src/components/Activity.svelte b/plugins/activity-resources/src/components/Activity.svelte index 0045dc9229..8a8d4ab110 100644 --- a/plugins/activity-resources/src/components/Activity.svelte +++ b/plugins/activity-resources/src/components/Activity.svelte @@ -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 diff --git a/plugins/lead-resources/src/components/CreateLead.svelte b/plugins/lead-resources/src/components/CreateLead.svelte index 3b61df220f..7cc1db2c01 100644 --- a/plugins/lead-resources/src/components/CreateLead.svelte +++ b/plugins/lead-resources/src/components/CreateLead.svelte @@ -75,7 +75,7 @@ await client.createMixin(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') } diff --git a/plugins/recruit-resources/src/components/CreateApplication.svelte b/plugins/recruit-resources/src/components/CreateApplication.svelte index 1553efa31b..6a1458bb12 100644 --- a/plugins/recruit-resources/src/components/CreateApplication.svelte +++ b/plugins/recruit-resources/src/components/CreateApplication.svelte @@ -82,8 +82,9 @@ await client.createMixin(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,