import { Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '~/types/prisma-schema';
export type WithSerializedDates<T> = T extends Date
? string
: T extends Array<infer R>
? Array<WithSerializedDates<R>>
: T extends object
? { [K in keyof T]: WithSerializedDates<T[K]> }
: T;
export const withoutDates = <T>(model: T): WithSerializedDates<T> =>
JSON.parse(JSON.stringify(model)) as WithSerializedDates<T>;
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit(): Promise<void> {
await this.$extends({
query: {
$allModels: {
$allOperations: async ({ query, args }) => {
return withoutDates(await query(args));
},
},
},
}).$connect();
}
}
import { Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '~/types/prisma-schema';
export type WithSerializedDates<T> = T extends Date
? string
: T extends Array<infer R>
? Array<WithSerializedDates<R>>
: T extends object
? { [K in keyof T]: WithSerializedDates<T[K]> }
: T;
export const withoutDates = <T>(model: T): WithSerializedDates<T> =>
JSON.parse(JSON.stringify(model)) as WithSerializedDates<T>;
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit(): Promise<void> {
await this.$extends({
query: {
$allModels: {
$allOperations: async ({ query, args }) => {
return withoutDates(await query(args));
},
},
},
}).$connect();
}
}