because I got bored of customising my CV for every job
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(config): use getOrThrow for configuration management

- Replace manual error throwing with ConfigService.getOrThrow()
- Update main.ts to use getOrThrow for PORT configuration
- Update PrismaService to use getOrThrow for DATABASE_URL
- Update AuthModule to use getOrThrow for JWT_SECRET
- Improve type safety and error handling for configuration

+11 -9
+4 -1
apps/server/src/main.ts
··· 1 1 import { NestFactory } from "@nestjs/core"; 2 2 import { ExpressAdapter } from "@nestjs/platform-express"; 3 3 import { ZodValidationPipe } from "nestjs-zod"; 4 + import { ConfigService } from "@nestjs/config"; 4 5 import { AppModule } from "./modules/app.module"; 5 6 6 7 async function bootstrap(): Promise<void> { 7 8 const app = await NestFactory.create(AppModule, new ExpressAdapter()); 9 + const configService = app.get(ConfigService); 8 10 9 11 // Enable CORS 10 12 app.enableCors({ ··· 16 18 17 19 app.useGlobalPipes(new ZodValidationPipe()); 18 20 19 - await app.listen(Number(process.env["PORT"] || "3000")); 21 + const port = configService.getOrThrow<number>("PORT"); 22 + await app.listen(Number(port)); 20 23 } 21 24 22 25 bootstrap();
+4 -6
apps/server/src/modules/auth/auth.module.ts
··· 6 6 import { AuthService } from "./auth.service"; 7 7 import { JwtAuthGuard } from "./jwt-auth.guard"; 8 8 import { MeResolver } from "./me.resolver"; 9 + import { UserMapper } from "./user.mapper"; 9 10 import { UserService } from "./user.service"; 10 11 11 12 @Global() ··· 16 17 JwtModule.registerAsync({ 17 18 imports: [ConfigModule], 18 19 useFactory: async (configService: ConfigService) => { 19 - const secret = configService.get<string>("JWT_SECRET"); 20 - if (!secret) { 21 - throw new Error("JWT_SECRET environment variable is required"); 22 - } 20 + const secret = configService.getOrThrow<string>("JWT_SECRET"); 23 21 return { 24 22 secret, 25 23 signOptions: { expiresIn: "24h" }, ··· 28 26 inject: [ConfigService], 29 27 }), 30 28 ], 31 - providers: [AuthService, UserService, AuthResolver, MeResolver, JwtAuthGuard], 32 - exports: [AuthService, UserService, JwtModule, JwtAuthGuard], 29 + providers: [AuthService, UserService, AuthResolver, MeResolver, JwtAuthGuard, UserMapper], 30 + exports: [AuthService, UserService, JwtModule, JwtAuthGuard, UserMapper], 33 31 }) 34 32 export class AuthModule {}
+3 -2
apps/server/src/modules/database/prisma.service.ts
··· 3 3 type OnModuleDestroy, 4 4 type OnModuleInit, 5 5 } from "@nestjs/common"; 6 + import { ConfigService } from "@nestjs/config"; 6 7 import { PrismaClient } from "@prisma/client"; 7 8 8 9 @Injectable() ··· 10 11 extends PrismaClient 11 12 implements OnModuleInit, OnModuleDestroy 12 13 { 13 - constructor() { 14 + constructor(private readonly configService: ConfigService) { 14 15 super({ 15 16 datasources: { 16 17 db: { 17 - url: process.env["DATABASE_URL"] ?? "postgresql://cv:cv@db:5432/cv", 18 + url: configService.getOrThrow<string>("DATABASE_URL"), 18 19 }, 19 20 }, 20 21 });