colinwilliams91 / nest-notes-template

Nest js | OpenAI | Socket-io multiplayer competitive creative writing game
https://secret-stories.vercel.app
0 stars 0 forks source link

PostgreSQL Entities and Tables #2

Open colinwilliams91 opened 11 months ago

colinwilliams91 commented 11 months ago

Validation Pipe and automated DTO (Data Transfer Objects) transform from string to alias Entity properties

typeorm-cli.config.ts initialized for later migration/refactor to NoSQL if decided. Using npx for typeorm CLI to preserve codebase optimization.

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule); // <-- Type allows exclusive Express methods
  app.useGlobalPipes(
    new ValidationPipe({
      transform: true, // <-- transforms DTOs properties datatypes to intended types (defaults transfer as Strings if not)
      whitelist: true, // <-- disallow users entering invalid properties to DTOs (invalid will be stripped/removed)
      forbidNonWhitelisted: true, // <-- disallows users by _stopping_ Payload process (throws error)
      transformOptions: {
        enableImplicitConversion: true, // <-- converts DTO datatypes from string to implied types globally (risk performance)
      },
    }),
  ); // <-- enforces validation rules for all incoming client Payloads automatically (body shapes)

  // app.useStaticAssets(join(__dirname, '..', 'public')); // <-- for shared image/static assets
  // app.setBaseViewsDir(join(__dirname, '..', 'views')); // <-- for `index.html` / views (components?)
  // app.setViewEngine('hbs');

  await app.listen(3000);
}
bootstrap();