I'm building an application with NestJS, and I've decided to adopt a service-oriented approach instead of using the Prisma client directly in other services. So, I'm extracting my database operations into separate methods within a service. Here's an example:
async findLimit(findLimitInput: FindLimitInput): Promise<Limit | null> {
const { where, select, include } = findLimitInput;
return this.prisma.limit.findUnique({
where: {
...SOFT_DELETE_CONDITION,
...where,
},
...addSelectOrIncludeOption({ select, include }),
});
}
This method returns the Limit type, which is generated by Prisma. The problem I run into is when I use the select or include statements. In these cases, the method would still return the Limit type, even though the actual returned object could be a subset or superset of the Limit model.
My question is, is there a way to maintain the same precision of typing that you get when using the client directly, but within my service-oriented NestJS architecture? Specifically I would like the returned type to reflect the actual fields selected or included in my query.