From 57cea4b4236bfa23a807c2b949ea7485ea15e9f6 Mon Sep 17 00:00:00 2001 From: Kasshern Date: Thu, 8 Feb 2024 09:19:39 -0600 Subject: [PATCH] feat: updates create workflow to nested write of create BpiAccount and Workflow --- .../agents/workflowsStorage.agent.ts | 51 +++++++++++++++---- .../createWorkflowCommand.handler.ts | 6 +-- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/examples/bri-3/src/bri/workgroup/workflows/agents/workflowsStorage.agent.ts b/examples/bri-3/src/bri/workgroup/workflows/agents/workflowsStorage.agent.ts index e0ac96685..79ac116a4 100644 --- a/examples/bri-3/src/bri/workgroup/workflows/agents/workflowsStorage.agent.ts +++ b/examples/bri-3/src/bri/workgroup/workflows/agents/workflowsStorage.agent.ts @@ -3,6 +3,7 @@ import { PrismaMapper } from '../../../../shared/prisma/prisma.mapper'; import { PrismaService } from '../../../../shared/prisma/prisma.service'; import { NOT_FOUND_ERR_MESSAGE } from '../api/err.messages'; import { Workflow } from '../models/workflow'; +import MerkleTree from 'merkletreejs'; @Injectable() export class WorkflowStorageAgent { @@ -55,23 +56,53 @@ export class WorkflowStorageAgent { }; }); - const newWorkflowModel = await this.prisma.workflow.create({ + const connectedOwnerBpiAccounts = + workflow.bpiAccount.ownerBpiSubjectAccounts.map((o) => { + return { + id: o.id, + }; + }); + + const newBpiAccountModel = await this.prisma.bpiAccount.create({ data: { - id: workflow.id, - name: workflow.name, - worksteps: { - connect: workstepIds, + nonce: workflow.bpiAccount.nonce, + ownerBpiSubjectAccounts: { + connect: connectedOwnerBpiAccounts, + }, + authorizationCondition: workflow.bpiAccount.authorizationCondition, + stateObjectProverSystem: workflow.bpiAccount.stateObjectProverSystem, + stateTree: { + create: { + id: workflow.bpiAccount.stateTreeId, + hashAlgName: workflow.bpiAccount.stateTree.hashAlgName, + tree: MerkleTree.marshalTree(workflow.bpiAccount.stateTree.tree), + }, + }, + historyTree: { + create: { + id: workflow.bpiAccount.historyTreeId, + hashAlgName: workflow.bpiAccount.historyTree.hashAlgName, + tree: MerkleTree.marshalTree(workflow.bpiAccount.historyTree.tree), + }, + }, + Workflow: { + create: [ + { + name: workflow.name, + worksteps: { + connect: workstepIds, + }, + workgroupId: workflow.workgroupId, + }, + ], }, - workgroupId: workflow.workgroupId, - bpiAccountId: workflow.bpiAccountId, }, include: { - worksteps: true, - bpiAccount: true, + Workflow: true, }, }); - return this.mapper.map(newWorkflowModel, Workflow); + return this.mapper.map(newBpiAccountModel.Workflow[0], Workflow); } async updateWorkflow(workflow: Workflow): Promise { diff --git a/examples/bri-3/src/bri/workgroup/workflows/capabilities/createWorkflow/createWorkflowCommand.handler.ts b/examples/bri-3/src/bri/workgroup/workflows/capabilities/createWorkflow/createWorkflowCommand.handler.ts index 1334ec201..7bec622a3 100644 --- a/examples/bri-3/src/bri/workgroup/workflows/capabilities/createWorkflow/createWorkflowCommand.handler.ts +++ b/examples/bri-3/src/bri/workgroup/workflows/capabilities/createWorkflow/createWorkflowCommand.handler.ts @@ -47,15 +47,11 @@ export class CreateWorkflowCommandHandler 'sample state object prover system', ); - const newBpiAccount = await this.accountStorageAgent.storeNewBpiAccount( - newBpiAccountCandidate, - ); - const newWorkflowCandidate = this.agent.createNewWorkflow( command.name, workstepsToConnect, command.workgroupId, - newBpiAccount, + newBpiAccountCandidate, ); const newWorkflow = await this.storageAgent.storeNewWorkflow(