-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.module.ts
55 lines (48 loc) · 1.37 KB
/
app.module.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {
INestApplication,
Injectable,
Module,
OnModuleInit,
} from '@nestjs/common';
import { AppController } from './app.controller';
import { ScheduleModule } from '@nestjs/schedule';
import { PrismaClient } from '@prisma/client';
const dbStr = 'file:./dev.db';
const createPrismaExtended = (prisma: PrismaService) => {
// TODO: uncomment the following line to "fix" the app WITH the ScheduleModule import (line 43)
// return prisma;
return prisma.$extends({
model: { environment: { async signUp(email: string) {} } },
});
};
export type PrismaServiceExtended = ReturnType<typeof createPrismaExtended>;
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
constructor() {
super({ datasources: { db: { url: dbStr } } });
}
async onModuleInit() {
await this.$connect();
}
async enableShutdownHooks(app: INestApplication) {
this.$on('beforeExit', async () => {
await app.close();
});
}
}
@Module({
imports: [
// TODO: Comment the following line to "fix" the app WITH the Extended Prisma Client (line 15)
ScheduleModule.forRoot(),
],
controllers: [AppController],
providers: [
PrismaService,
{
provide: 'PrismaClientExtended',
inject: [PrismaService],
useFactory: (prisma: PrismaService) => createPrismaExtended(prisma),
},
],
})
export class AppModule {}