Skip to content

Commit e40779e

Browse files
ymc9jasonmacdonaldJason MacDonald
authored
merge dev to main (v2.3.0) (#1582)
Co-authored-by: Jason MacDonald <[email protected]> Co-authored-by: Jason MacDonald <[email protected]>
1 parent edfe9cf commit e40779e

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

packages/server/src/nestjs/zenstack.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ZenStackModuleOptions {
1212
/**
1313
* A callback for getting an enhanced `PrismaClient`.
1414
*/
15-
getEnhancedPrisma: () => unknown;
15+
getEnhancedPrisma: (model?: string | symbol ) => unknown;
1616
}
1717

1818
/**
@@ -79,7 +79,7 @@ export class ZenStackModule {
7979
{
8080
get(_target, prop) {
8181
// eslint-disable-next-line @typescript-eslint/no-explicit-any
82-
const enhancedPrisma: any = getEnhancedPrisma();
82+
const enhancedPrisma: any = getEnhancedPrisma(prop);
8383
if (!enhancedPrisma) {
8484
throw new Error('`getEnhancedPrisma` must return a valid Prisma client');
8585
}

packages/server/tests/adapter/nestjs.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,53 @@ describe('NestJS adapter tests', () => {
160160
const postSvc = app.get('PostService');
161161
await expect(postSvc.findAll()).resolves.toHaveLength(1);
162162
});
163+
164+
it('pass property', async () => {
165+
const { prisma, enhanceRaw } = await loadSchema(schema);
166+
167+
await prisma.user.create({
168+
data: {
169+
posts: {
170+
create: [
171+
{ title: 'post1', published: true },
172+
{ title: 'post2', published: false },
173+
],
174+
},
175+
},
176+
});
177+
178+
const moduleRef = await Test.createTestingModule({
179+
imports: [
180+
ZenStackModule.registerAsync({
181+
useFactory: (prismaService) => ({
182+
getEnhancedPrisma: (prop) => {
183+
return prop === 'post' ? prismaService : enhanceRaw(prismaService, { user: { id: 2 } });
184+
},
185+
}),
186+
inject: ['PrismaService'],
187+
extraProviders: [
188+
{
189+
provide: 'PrismaService',
190+
useValue: prisma,
191+
},
192+
],
193+
}),
194+
],
195+
providers: [
196+
{
197+
provide: 'PostService',
198+
useFactory: (enhancedPrismaService) => ({
199+
findAll: () => enhancedPrismaService.post.findMany(),
200+
}),
201+
inject: [ENHANCED_PRISMA],
202+
},
203+
],
204+
}).compile();
205+
206+
const app = moduleRef.createNestApplication();
207+
await app.init();
208+
209+
const postSvc = app.get('PostService');
210+
await expect(postSvc.findAll()).resolves.toHaveLength(2);
211+
});
163212
});

0 commit comments

Comments
 (0)