feat: Initialize NestJS backend project with Prisma, core modules, configuration, and common utilities.

This commit is contained in:
pradeepkumar
2025-12-18 23:05:04 +05:30
commit 7990846711
28 changed files with 21284 additions and 0 deletions

2
src/prisma/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export * from './prisma.module';
export * from './prisma.service';

View File

@@ -0,0 +1,9 @@
import { Global, Module } from '@nestjs/common';
import { PrismaService } from './prisma.service';
@Global()
@Module({
providers: [PrismaService],
exports: [PrismaService],
})
export class PrismaModule {}

View File

@@ -0,0 +1,45 @@
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Injectable()
export class PrismaService
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
constructor() {
super({
log:
process.env.NODE_ENV === 'development'
? ['query', 'info', 'warn', 'error']
: ['error'],
});
}
async onModuleInit() {
await this.$connect();
}
async onModuleDestroy() {
await this.$disconnect();
}
async cleanDatabase() {
if (process.env.NODE_ENV === 'production') {
throw new Error('cleanDatabase is not allowed in production');
}
const models = Reflect.ownKeys(this).filter(
(key) => typeof key === 'string' && !key.startsWith('_') && !key.startsWith('$'),
);
return Promise.all(
models.map((modelKey) => {
const model = this[modelKey as string];
if (model && typeof model.deleteMany === 'function') {
return model.deleteMany();
}
return Promise.resolve();
}),
);
}
}