refactor codebase and pothos structure

This commit is contained in:
2024-10-07 10:07:08 +07:00
parent 29ec9c5360
commit dfa6b35399
31 changed files with 997 additions and 664 deletions

View File

@@ -1,8 +1,9 @@
import { Module } from '@nestjs/common';
import { Global, Module } from '@nestjs/common';
import { PrismaService } from './prisma.service';
@Global()
@Module({
providers: [PrismaService],
exports: [PrismaService], // Export PrismaService so other modules can use it
exports: [PrismaService],
})
export class PrismaModule {}

View File

@@ -1,13 +1,32 @@
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import {
ConsoleLogger,
INestApplication,
Injectable,
OnModuleInit,
} from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
async onModuleInit() {
await this.$connect();
export class PrismaService extends PrismaClient implements OnModuleInit {
private readonly logger = new ConsoleLogger(PrismaService.name);
constructor() {
super({
log: ['query', 'info', 'warn', 'error'],
});
}
async onModuleDestroy() {
await this.$disconnect();
async onModuleInit() {
this.logger.log('Try to connect database...');
await this.$connect();
this.logger.log('Connected.');
}
async enableShutdownHooks(app: INestApplication) {
this.$on('beforeExit' as never, async () => {
this.logger.log('Wait for application closing...');
await app.close();
});
}
}