Hello NestJS Community,
I am experiencing an issue with my NestJS application which uses Prisma with MongoDB. The problem arises with the serialization of date fields in API responses.
Problem Description:
In my NestJS application, I have Prisma models with DateTime fields. These fields are correctly stored and retrieved from MongoDB, and they appear as expected when logged in the console at both the service and controller levels. However, when these data objects are sent as responses to the client, the date fields are serialized as empty objects instead of proper date strings or formats.
async findOne(where: Prisma.UserWhereUniqueInput): Promise<Partial<User> | null> {
const user = await this.prismaService.user.findUnique({ where });
if (!user) {
throw new NotFoundException(`User not found`);
}
console.log(user); // Date is correctly shown here
return user;
}