feat: add lottery results display page
- Add LOTTERY_RESULTS system phase - Add /screen/lottery-results route - Add LotteryResultsView component - Add database connection management (db.ts) - Update DrawResult schema to remove User relation - Add awardIcon field to VoteResultsView Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,6 @@ model User {
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
votes Vote[]
|
||||
drawResults DrawResult[]
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
@@ -82,14 +81,12 @@ model DrawResult {
|
||||
drawId String @map("draw_id")
|
||||
prizeLevel String @map("prize_level") @db.VarChar(20)
|
||||
prizeName String @map("prize_name") @db.VarChar(100)
|
||||
winnerId String @map("winner_id")
|
||||
winnerId String @map("winner_id") @db.VarChar(100)
|
||||
winnerName String @map("winner_name") @db.VarChar(100)
|
||||
winnerDepartment String @map("winner_department") @db.VarChar(100)
|
||||
drawnAt DateTime @default(now()) @map("drawn_at")
|
||||
drawnBy String @map("drawn_by") @db.VarChar(100)
|
||||
|
||||
winner User @relation(fields: [winnerId], references: [id])
|
||||
|
||||
@@index([drawId])
|
||||
@@index([prizeLevel])
|
||||
@@index([winnerId])
|
||||
|
||||
51
packages/server/src/config/db.ts
Normal file
51
packages/server/src/config/db.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Database configuration using Prisma Client
|
||||
*/
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { logger } from '../utils/logger';
|
||||
|
||||
// Prisma Client instance with logging in development
|
||||
export const prisma = new PrismaClient({
|
||||
log: process.env.NODE_ENV === 'development'
|
||||
? ['query', 'info', 'warn', 'error']
|
||||
: ['error'],
|
||||
});
|
||||
|
||||
/**
|
||||
* Connect to database
|
||||
*/
|
||||
export async function connectDatabase(): Promise<void> {
|
||||
try {
|
||||
await prisma.$connect();
|
||||
logger.info('Database connected successfully');
|
||||
} catch (error) {
|
||||
logger.error({ error }, 'Failed to connect to database');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from database
|
||||
*/
|
||||
export async function disconnectDatabase(): Promise<void> {
|
||||
try {
|
||||
await prisma.$disconnect();
|
||||
logger.info('Database disconnected');
|
||||
} catch (error) {
|
||||
logger.error({ error }, 'Error disconnecting from database');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Health check for database connection
|
||||
*/
|
||||
export async function checkDatabaseHealth(): Promise<boolean> {
|
||||
try {
|
||||
await prisma.$queryRaw`SELECT 1`;
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.error({ error }, 'Database health check failed');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { createServer } from 'http';
|
||||
import { app, logger } from './app';
|
||||
import { config } from './config';
|
||||
import { connectRedis } from './config/redis';
|
||||
import { connectDatabase, disconnectDatabase } from './config/db';
|
||||
import { initializeSocket } from './socket';
|
||||
import { loadLuaScripts } from './services/vote.service';
|
||||
import { loadVotingScripts } from './services/voting.engine';
|
||||
@@ -11,6 +12,10 @@ import { participantService } from './services/participant.service';
|
||||
|
||||
async function main(): Promise<void> {
|
||||
try {
|
||||
// Connect to Database
|
||||
logger.info('Connecting to Database...');
|
||||
await connectDatabase();
|
||||
|
||||
// Connect to Redis
|
||||
logger.info('Connecting to Redis...');
|
||||
await connectRedis();
|
||||
@@ -50,6 +55,9 @@ async function main(): Promise<void> {
|
||||
const shutdown = async (signal: string) => {
|
||||
logger.info({ signal }, 'Shutdown signal received');
|
||||
|
||||
// Disconnect from database
|
||||
await disconnectDatabase();
|
||||
|
||||
httpServer.close(() => {
|
||||
logger.info('HTTP server closed');
|
||||
process.exit(0);
|
||||
|
||||
Reference in New Issue
Block a user