feat: add initial project configuration and smoke tests
- Created pnpm workspace configuration to manage packages. - Added a placeholder .gitkeep file in the scripts directory. - Implemented a smoke test script to validate core API and web endpoints. - Established TypeScript base configuration for consistent compilation settings. - Introduced Turbo configuration for task management and build processes.
This commit is contained in:
33
packages/api/src/prisma/__tests__/prisma.service.spec.ts
Normal file
33
packages/api/src/prisma/__tests__/prisma.service.spec.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { PrismaService } from '../prisma.service.js';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
describe('PrismaService', () => {
|
||||
let service: PrismaService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
PrismaService,
|
||||
{
|
||||
provide: ConfigService,
|
||||
useValue: {
|
||||
getOrThrow: vi.fn().mockReturnValue('postgresql://test:test@localhost:5432/test'),
|
||||
},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
service = module.get<PrismaService>(PrismaService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
it('should expose PrismaClient methods directly (extends pattern)', () => {
|
||||
expect(typeof service.$connect).toBe('function');
|
||||
expect(typeof service.$disconnect).toBe('function');
|
||||
});
|
||||
});
|
||||
9
packages/api/src/prisma/prisma.module.ts
Normal file
9
packages/api/src/prisma/prisma.module.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { PrismaService } from './prisma.service.js';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [PrismaService],
|
||||
exports: [PrismaService],
|
||||
})
|
||||
export class PrismaModule {}
|
||||
33
packages/api/src/prisma/prisma.service.ts
Normal file
33
packages/api/src/prisma/prisma.service.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { PrismaClient } from '../generated/prisma/client';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
|
||||
/**
|
||||
* NestJS-managed Prisma service for Prisma 7.
|
||||
*
|
||||
* Follows the official NestJS + Prisma 7 recipe:
|
||||
* - Uses `prisma-client` generator with `moduleFormat = "cjs"`
|
||||
* - Extends PrismaClient directly for full type-safe API access
|
||||
* - Uses PrismaPg driver adapter with connectionString
|
||||
*
|
||||
* Usage in feature modules:
|
||||
* constructor(private readonly prisma: PrismaService) {}
|
||||
* await this.prisma.placeholder.findMany();
|
||||
*/
|
||||
@Injectable()
|
||||
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
||||
constructor(configService: ConfigService) {
|
||||
const databaseUrl = configService.getOrThrow<string>('DATABASE_URL');
|
||||
const adapter = new PrismaPg({ connectionString: databaseUrl });
|
||||
super({ adapter });
|
||||
}
|
||||
|
||||
async onModuleInit(): Promise<void> {
|
||||
await this.$connect();
|
||||
}
|
||||
|
||||
async onModuleDestroy(): Promise<void> {
|
||||
await this.$disconnect();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user