fix: complete first version issue remediation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Injectable, OnModuleDestroy } from '@nestjs/common';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { requestContext } from '../common/request-context';
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService extends PrismaClient implements OnModuleDestroy {
|
||||
@@ -11,6 +12,24 @@ export class PrismaService extends PrismaClient implements OnModuleDestroy {
|
||||
'postgresql://cmpp:cmpp_password@localhost:5432/cmpp_platform?schema=public',
|
||||
),
|
||||
});
|
||||
const operationLog = this.operationLog;
|
||||
Object.defineProperty(this, 'operationLog', {
|
||||
value: new Proxy(operationLog, {
|
||||
get(target, property, receiver) {
|
||||
if (property === 'create') {
|
||||
return (args: { data: Record<string, unknown> }) => {
|
||||
const ipAddress = requestContext.getStore()?.ipAddress;
|
||||
return (target.create as (input: unknown) => unknown)({
|
||||
...args,
|
||||
data: { ...args.data, ipAddress: typeof args.data.ipAddress === 'string' ? args.data.ipAddress : ipAddress },
|
||||
});
|
||||
};
|
||||
}
|
||||
const value = Reflect.get(target, property, receiver);
|
||||
return typeof value === 'function' ? value.bind(target) : value;
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
async onModuleDestroy() {
|
||||
|
||||
Reference in New Issue
Block a user