feat: keep deletions restorable and confirm a pipeline's deals before it is removed
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,13 +1,34 @@
|
||||
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
||||
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 extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
||||
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 this.$connect();
|
||||
await client.$connect();
|
||||
}
|
||||
|
||||
async onModuleDestroy() {
|
||||
await this.$disconnect();
|
||||
await client.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
export type PrismaServiceClient = typeof client;
|
||||
|
||||
Reference in New Issue
Block a user