Hi. In a project I want to implement domain driven design in some modules. The problem I seem to have is with Prisma. I've been loving it nevertheless I have no idea how to reflect changes in aggregates and other domain concepts to prisma queries. Let's assume I have an aggregate Cart which has many entities Cart_Product[]. To map my Cart aggregate to prisma.cart.create() I would need to provide create data for cart and products. For update I would need to provide similar data which is bearable. However, when it comes to deleting entities how should I track which Ids I need to use for
prisma.cart.update({
where: {
id
},
{
data: {
cartProducts: {
deleteMany: {
productId: {
in: productsToDelete
}
}
}
}
}
})
Keeping it somewhere in my aggregate would violate DDD principles, I've never seen keeping ids of deleted entities on aggregate. Such mapping from my domain classes to Prisma objects would make no sense in my opinion, especially when I'm planning to have some aggregates with even more entities. In projects in .NET I can see that they do not do such mappers for their orm. I've been looking on typeorm and I can see it's possible to write sth like this
const user = new User()
user.name = "John"
user.photos = [photo1, photo2]
await dataSource.manager.save(user)
and I assume that a code like this (ofc, not exactly, just a pseudo-code)
cartAggregate = cartAggregate.products.filter(p => p.id !== productToDeleteId);
await cartAggregate.save();
could be achievable using TypeORM. Nevertheless I'm not very familiar with TypeORM so I may have misunderstood this concept and it's the first time doing DDD in NestJS so I would really appreciate Your suggestions and advice 🙂