Add relation action (#9970)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2025-09-30 11:19:59 +07:00
committed by GitHub
parent 764d963885
commit 66bdcc324f
7 changed files with 412 additions and 231 deletions
@@ -120,7 +120,7 @@ export async function AddRelation (
params: MethodParams<Relation>,
execution: Execution,
control: ProcessControl
): Promise<ExecuteResult | undefined> {
): Promise<ExecuteResult> {
const _id = generateId<Relation>()
const association = params.association as Ref<Association>
if (isEmpty(association)) {
@@ -141,6 +141,14 @@ export async function AddRelation (
docA,
docB
}
const exists = await control.client.findOne(core.class.Relation, { docA, docB, association })
if (exists !== undefined) {
return {
txes: [],
rollback: [],
context: []
}
}
const resTx = control.client.txFactory.createTxCreateDoc(core.class.Relation, core.space.Workspace, data, _id)
const res: Tx[] = [resTx]
const rollback: Tx[] = [control.client.txFactory.createTxRemoveDoc(core.class.Relation, core.space.Workspace, _id)]