I'm confused.
I'm building an API that uses prisma as ORM, as per the documentation (https://docs.nestjs.com/recipes/prisma)
Now, If I use this service in a controller, everything works as expected. But if I use the very same method in a custom service, and returns the result in my controller, the returned type is not the same, and therefore, I get type errors
// my service
/**
* Find one user
*/
async findOne(userWhereUniqueInput: Prisma.UserWhereUniqueInput) {
// Throw an error if the user doesn't exist
return this.prisma.user.findUniqueOrThrow({
where: userWhereUniqueInput,
});
}
// [...]
// my controller
/**
* Find one user
*/
@Get()
async findOne(userWhereUniqueInput: Prisma.UserWhereUniqueInput) {
const user2 = this.prismaService.user.findUnique({
where: userWhereUniqueInput,
});
const user2company = user2.company() // works just fine
const user = await this.usersService.findOne(userWhereUniqueInput);
const userCompany = user.company(); //raises an error: "Property 'company' does not exist on type..."
}
Did I miss something ? In both cases, I use the very same method provided by Prisma
Documentation | NestJS - A progressive Node.js framework
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).