Skip to content

Commit

Permalink
Implement generic map method for prisma mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
ognjenkurtic committed Jan 24, 2024
1 parent d3319ca commit dce2003
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export class BpiMessageStorageAgent {
return undefined;
}

const bpiMessage =
this.mapper.mapBpiMessagePrismaModelToDomainObject(bpiMessageModel);
const bpiMessage = this.mapper.map(bpiMessageModel, BpiMessage);
bpiMessage.updateContent(
await this.encryptionService.decrypt(bpiMessage.content),
);
Expand All @@ -35,9 +34,7 @@ export class BpiMessageStorageAgent {
const bpiMessageModels = await this.prisma.message.findMany();

return bpiMessageModels.map((bpiMessageModel) => {
return this.mapper.mapBpiMessagePrismaModelToDomainObject(
bpiMessageModel,
);
return this.mapper.map(bpiMessageModel, BpiMessage);
});
}

Expand All @@ -54,9 +51,7 @@ export class BpiMessageStorageAgent {
include: { fromBpiSubject: true, toBpiSubject: true },
});

return this.mapper.mapBpiMessagePrismaModelToDomainObject(
newBpiMessageModel,
);
return this.mapper.map(newBpiMessageModel, BpiMessage);
}

async updateBpiMessage(bpiMessage: BpiMessage): Promise<BpiMessage> {
Expand All @@ -73,9 +68,7 @@ export class BpiMessageStorageAgent {
include: { fromBpiSubject: true, toBpiSubject: true },
});

return this.mapper.mapBpiMessagePrismaModelToDomainObject(
updatedBpiMessageModel,
);
return this.mapper.map(updatedBpiMessageModel, BpiMessage);
}

async deleteBpiMessage(bpiMessage: BpiMessage): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ export class BpiSubjectAccountStorageAgent {
return undefined;
}

return this.mapper.mapBpiSubjectAccountPrismaModelToDomainObject(
bpiSubjectAccountModel,
);
return this.mapper.map(bpiSubjectAccountModel, BpiSubjectAccount);
}

async getAllBpiSubjectAccounts(): Promise<BpiSubjectAccount[]> {
Expand All @@ -37,7 +35,7 @@ export class BpiSubjectAccountStorageAgent {
include: { ownerBpiSubject: true, creatorBpiSubject: true },
});
return bpiSubjectAccountsModels.map((bp) => {
return this.mapper.mapBpiSubjectAccountPrismaModelToDomainObject(bp);
return this.mapper.map(bp, BpiSubjectAccount);
});
}

Expand All @@ -57,9 +55,7 @@ export class BpiSubjectAccountStorageAgent {
include: { ownerBpiSubject: true, creatorBpiSubject: true },
});

return this.mapper.mapBpiSubjectAccountPrismaModelToDomainObject(
newBpiSubjectAccountModel,
);
return this.mapper.map(newBpiSubjectAccountModel, BpiSubjectAccount);
}

async updateBpiSubjectAccount(
Expand All @@ -79,9 +75,7 @@ export class BpiSubjectAccountStorageAgent {
include: { ownerBpiSubject: true, creatorBpiSubject: true },
});

return this.mapper.mapBpiSubjectAccountPrismaModelToDomainObject(
newBpiSubjectAccountModel,
);
return this.mapper.map(newBpiSubjectAccountModel, BpiSubjectAccount);
}

async deleteBpiSubjectAccount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ export class BpiSubjectStorageAgent extends PrismaService {
return undefined;
}

return this.mapper.mapBpiSubjectPrismaModelToDomainObject(bpiSubjectModel);
return this.mapper.map(bpiSubjectModel, BpiSubject);
}

async getAllBpiSubjects(): Promise<BpiSubject[]> {
const bpiSubjectModels = await this.prisma.bpiSubject.findMany();
return bpiSubjectModels.map((bpiSubjectModel) => {
return this.mapper.mapBpiSubjectPrismaModelToDomainObject(
bpiSubjectModel,
);
return this.mapper.map(bpiSubjectModel, BpiSubject);
});
}

Expand All @@ -49,9 +47,7 @@ export class BpiSubjectStorageAgent extends PrismaService {
include: { roles: true },
});
return bpiSubjectModels.map((bpiSubjectModel) => {
return this.mapper.mapBpiSubjectPrismaModelToDomainObject(
bpiSubjectModel,
);
return this.mapper.map(bpiSubjectModel, BpiSubject);
});
}

Expand All @@ -65,9 +61,7 @@ export class BpiSubjectStorageAgent extends PrismaService {
if (!bpiSubjectRole) {
throw new NotFoundException(NOT_FOUND_ERR_MESSAGE);
}
return this.mapper.mapBpiSubjectRolePrismaModelToDomainObject(
bpiSubjectRole,
);
return this.mapper.map(bpiSubjectRole, BpiSubjectRole);
}

async storeNewBpiSubject(bpiSubject: BpiSubject): Promise<BpiSubject> {
Expand All @@ -85,9 +79,7 @@ export class BpiSubjectStorageAgent extends PrismaService {
},
});

return this.mapper.mapBpiSubjectPrismaModelToDomainObject(
newBpiSubjectModel,
);
return this.mapper.map(newBpiSubjectModel, BpiSubject);
}

async updateBpiSubject(bpiSubject: BpiSubject): Promise<BpiSubject> {
Expand All @@ -104,9 +96,7 @@ export class BpiSubjectStorageAgent extends PrismaService {
},
},
});
return this.mapper.mapBpiSubjectPrismaModelToDomainObject(
updatedBpiSubjectModel,
);
return this.mapper.map(updatedBpiSubjectModel, BpiSubject);
}

async deleteBpiSubject(bpiSubject: BpiSubject): Promise<void> {
Expand All @@ -127,6 +117,6 @@ export class BpiSubjectStorageAgent extends PrismaService {
if (!bpiSubjectModel) {
throw new NotFoundException(NOT_FOUND_ERR_MESSAGE);
}
return this.mapper.mapBpiSubjectPrismaModelToDomainObject(bpiSubjectModel);
return this.mapper.map(bpiSubjectModel, BpiSubject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class BpiAccountStorageAgent {
throw new NotFoundException(NOT_FOUND_ERR_MESSAGE);
}

return this.mapper.mapBpiAccountPrismaModelToDomainObject(bpiAccountModel);
return this.mapper.map(bpiAccountModel, BpiAccount);
}

async getAllBpiAccounts(): Promise<BpiAccount[]> {
Expand All @@ -50,7 +50,7 @@ export class BpiAccountStorageAgent {
});

return bpiAccountModels.map((bp) => {
return this.mapper.mapBpiAccountPrismaModelToDomainObject(bp);
return this.mapper.map(bp, BpiAccount);
});
}

Expand Down Expand Up @@ -87,9 +87,7 @@ export class BpiAccountStorageAgent {
},
});

return this.mapper.mapBpiAccountPrismaModelToDomainObject(
newBpiAccountModel,
);
return this.mapper.map(newBpiAccountModel, BpiAccount);
}

async updateBpiAccount(bpiAccount: BpiAccount): Promise<BpiAccount> {
Expand All @@ -103,9 +101,7 @@ export class BpiAccountStorageAgent {
},
});

return this.mapper.mapBpiAccountPrismaModelToDomainObject(
newBpiAccountModel,
);
return this.mapper.map(newBpiAccountModel, BpiAccount);
}

async deleteBpiAccount(bpiAccount: BpiAccount): Promise<void> {
Expand Down Expand Up @@ -144,8 +140,6 @@ export class BpiAccountStorageAgent {
return undefined;
}

return this.mapper.mapBpiAccountStateTreeLeafValuePrismaModelToDomainObject(
stateLeafValues,
);
return this.mapper.map(stateLeafValues, StateTreeLeafValueContent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export class TransactionStorageAgent {
include: { fromBpiSubjectAccount: true, toBpiSubjectAccount: true },
});
return transactionModels.map((transactionModel) => {
return this.mapper.mapTransactionPrismaModelToDomainObject(
transactionModel,
);
return this.mapper.map(transactionModel, Transaction);
});
}

Expand All @@ -46,9 +44,7 @@ export class TransactionStorageAgent {
throw new NotFoundException(NOT_FOUND_ERR_MESSAGE);
}

return this.mapper.mapTransactionPrismaModelToDomainObject(
transactionModel,
);
return this.mapper.map(transactionModel, Transaction);
}

async getTopNTransactionsByStatus(
Expand All @@ -75,9 +71,7 @@ export class TransactionStorageAgent {
});

return transactionModels.map((transactionModel) => {
return this.mapper.mapTransactionPrismaModelToDomainObject(
transactionModel,
);
return this.mapper.map(transactionModel, Transaction);
});
}

Expand Down Expand Up @@ -110,9 +104,7 @@ export class TransactionStorageAgent {
},
});

return this.mapper.mapTransactionPrismaModelToDomainObject(
newTransactionModel,
);
return this.mapper.map(newTransactionModel, Transaction);
}

async updateTransaction(transaction: Transaction): Promise<Transaction> {
Expand All @@ -124,9 +116,7 @@ export class TransactionStorageAgent {
},
});

return this.mapper.mapTransactionPrismaModelToDomainObject(
updatedTransactionModel,
);
return this.mapper.map(updatedTransactionModel, Transaction);
}

async updateTransactionStatus(
Expand All @@ -141,9 +131,7 @@ export class TransactionStorageAgent {
},
});

return this.mapper.mapTransactionPrismaModelToDomainObject(
updatedTransaction,
);
return this.mapper.map(updatedTransaction, Transaction);
}

async deleteTransaction(transaction: Transaction): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export class WorkflowStorageAgent {
throw new NotFoundException(WORKFLOW_NOT_FOUND_ERR_MESSAGE);
}

return this.mapper.mapWorkflowPrismaModelToDomainObject(workflowModel);
return this.mapper.map(workflowModel, Workflow);
}

async getAllWorkflows(): Promise<Workflow[]> {
const workflowModels = await this.prisma.workflow.findMany({
include: { worksteps: true },
});
return workflowModels.map((w) => {
return this.mapper.mapWorkflowPrismaModelToDomainObject(w);
return this.mapper.map(w, Workflow);
});
}

Expand All @@ -44,7 +44,7 @@ export class WorkflowStorageAgent {
include: { worksteps: true },
});
return workflowModels.map((w) => {
return this.mapper.mapWorkflowPrismaModelToDomainObject(w);
return this.mapper.map(w, Workflow);
});
}

Expand All @@ -71,7 +71,7 @@ export class WorkflowStorageAgent {
},
});

return this.mapper.mapWorkflowPrismaModelToDomainObject(newWorkflowModel);
return this.mapper.map(newWorkflowModel, Workflow);
}

async updateWorkflow(workflow: Workflow): Promise<Workflow> {
Expand All @@ -95,9 +95,7 @@ export class WorkflowStorageAgent {
},
});

return this.mapper.mapWorkflowPrismaModelToDomainObject(
updatedWorkflowModel,
);
return this.mapper.map(updatedWorkflowModel, Workflow);
}

async deleteWorkflow(workflow: Workflow): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class WorkgroupStorageAgent {
throw new NotFoundException(WORKGROUP_NOT_FOUND_ERR_MESSAGE);
}

return this.mapper.mapWorkgroupPrismaModelToDomainObject(workgroupModel);
return this.mapper.map(workgroupModel, Workgroup);
}

async createNewWorkgroup(workgroup: Workgroup): Promise<Workgroup> {
Expand Down Expand Up @@ -67,7 +67,7 @@ export class WorkgroupStorageAgent {
},
});

return this.mapper.mapWorkgroupPrismaModelToDomainObject(newWorkgroupModel);
return this.mapper.map(newWorkgroupModel, Workgroup);
}

async updateWorkgroup(workgroup: Workgroup): Promise<Workgroup> {
Expand Down Expand Up @@ -105,9 +105,7 @@ export class WorkgroupStorageAgent {
},
});

return this.mapper.mapWorkgroupPrismaModelToDomainObject(
updatedWorkgroupModel,
);
return this.mapper.map(updatedWorkgroupModel, Workgroup);
}

async deleteWorkgroup(workgroup: Workgroup): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export class WorkstepStorageAgent {
throw new NotFoundException(NOT_FOUND_ERR_MESSAGE);
}

return this.mapper.mapWorkstepPrismaModelToDomainObject(workstepModel);
return this.mapper.map(workstepModel, Workstep);
}

async getAllWorksteps(): Promise<Workstep[]> {
const workstepModels = await this.prisma.workstep.findMany();
return workstepModels.map((workstepModel) => {
return this.mapper.mapWorkstepPrismaModelToDomainObject(workstepModel);
return this.mapper.map(workstepModel, Workstep);
});
}

Expand All @@ -40,25 +40,23 @@ export class WorkstepStorageAgent {
},
});
return workstepModels.map((w) => {
return this.mapper.mapWorkstepPrismaModelToDomainObject(w);
return this.mapper.map(w, Workstep);
});
}

async storeNewWorkstep(workstep: Workstep): Promise<Workstep> {
const newWorkstepModel = await this.prisma.workstep.create({
data: workstep,
});
return this.mapper.mapWorkstepPrismaModelToDomainObject(newWorkstepModel);
return this.mapper.map(newWorkstepModel, Workstep);
}

async updateWorkstep(workstep: Workstep): Promise<Workstep> {
const updatedWorkstepModel = await this.prisma.workstep.update({
where: { id: workstep.id },
data: workstep,
});
return this.mapper.mapWorkstepPrismaModelToDomainObject(
updatedWorkstepModel,
);
return this.mapper.map(updatedWorkstepModel, Workstep);
}

async deleteWorkstep(workstep: Workstep): Promise<void> {
Expand Down
Loading

0 comments on commit dce2003

Please sign in to comment.