Files
CRM_Montzar/apps/api/src/prisma/prisma.service.ts
T

35 lines
1007 B
TypeScript

import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { withDeletionArchive } from '../deletions/deletion-archive';
const base = new PrismaClient();
const client = withDeletionArchive(base);
export interface PrismaService extends PrismaClient {}
@Injectable()
export class PrismaService implements OnModuleInit, OnModuleDestroy {
constructor() {
return new Proxy(this, {
get: (target, prop, receiver) => {
if (Reflect.has(target, prop)) return Reflect.get(target, prop, receiver);
const value = (client as unknown as Record<PropertyKey, unknown>)[prop];
if (typeof value === 'function') {
return (value as (...args: unknown[]) => unknown).bind(client);
}
return value;
},
});
}
async onModuleInit() {
await client.$connect();
}
async onModuleDestroy() {
await client.$disconnect();
}
}
export type PrismaServiceClient = typeof client;