Create aggregate service when needed. Aggregate service imports multiple smaller services and perform business logics that each individual smaller service cant.
E.g. Creating promotion transaction requires promotion and transaction service promotion-transaction.service
A piece of code that its sole reponsiblitiy is to deal with database. Repository should be created as per business entity.
Examples:
Transaction
is an business entityPromotion
is an business entity
Service should not have direct access to PrismaAbstract
. They should import repository to perform data operations
Why? Because PrismaAbstract
is not abstract enough to perform complex queries and the service itself would need to access prisma directly again
Instead the current implementation of PrismaAbstract
can be used as PrismaRepository which its sole purpose is to make a generic repository to access data.
Optimally, service should only contain business logic that doesnt care about db implementation
Code for reference:
transaction.repository.ts
- Perform queries for transactions datatransaction.service.ts
- Using repositories
https://betterprogramming.pub/clean-node-js-architecture-with-nestjs-and-typescript-34b9398d790f