-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbypass.ts
31 lines (25 loc) · 1.06 KB
/
bypass.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { PrismaModule, PrismaService } from 'nestjs-prisma';
const useFactory = (prisma: PrismaService) => {
console.log('Bypass Client useFactory called');
return prisma.$extends({
query: {
$allModels: {
async $allOperations({ args, query }) {
const [, result] = await prisma.$transaction([
prisma.$executeRaw`SELECT set_config('tenancy.tenant_id', '0', TRUE), set_config('tenancy.bypass', '1', TRUE)`,
query(args),
]);
return result;
},
},
},
});
};
export type ExtendedBypassReqScopeClient = ReturnType<typeof useFactory>;
export const BYPASS_REQ_SCOPE_CLIENT_TOKEN = Symbol('BYPASS_REQ_SCOPE_CLIENT_TOKEN');
export const PrismaBypassReqScopeClientProvider = {
provide: BYPASS_REQ_SCOPE_CLIENT_TOKEN,
imports: [PrismaModule],
inject: [PrismaService],
useFactory,
};