Skip to content

Commit

Permalink
feat: updates create workflow to nested write of create BpiAccount an…
Browse files Browse the repository at this point in the history
…d Workflow
  • Loading branch information
Kasshern authored and ognjenkurtic committed Feb 28, 2024
1 parent 958671d commit 57cea4b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Workflow> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 57cea4b

Please sign in to comment.