Posts

Showing posts with the label validation

NestJS Controller and Swagger Guide

Image
Introduction NestJS is a progressive Node.js framework built with TypeScript, facilitating the development of efficient and scalable server-side applications. By default, NestJS uses Express as its core HTTP processing library. Key advantages include a tight modular architecture inspired by Angular and strong TypeScript support to reduce code errors. Controllers serve as the layer for processing incoming requests and returning responses to the client side. Their primary responsibility is to receive HTTP requests, route data to business logic services, and coordinate the returned result in the correct format. Swagger is a powerful suite of tools used for designing, building, and documenting RESTful APIs developed based on the OpenAPI data format specification. In NestJS, it helps automatically generate an intuitive UI interface for testing endpoints, enabling developers and stakeholders to understand the API structure without directly reading the source code. Detail After creating the N...

Using TypeORM in a NestJS Project

Image
Introduction TypeORM is a powerful ORM (Object-Relational Mapper) library for the Node.js ecosystem, written in TypeScript. It allows developers to interact with databases using classes and objects instead of writing complex raw SQL queries. Key Advantages Excellent TypeScript support: Fully leverages decorators and type-checking, helping detect errors during development instead of at runtime. Supports multiple databases: Compatible with popular database management systems such as MySQL, PostgreSQL, SQLite, etc. Flexible patterns (Data Mapper & Active Record): Lets you choose the appropriate implementation style depending on project size (Data Mapper for large, complex projects; Active Record for smaller, quick projects). Migration management: Provides powerful tools to manage database schema changes systematically, helping synchronize changes across development teams. Query Builder: In addition to object-based operations, TypeORM provides a Query Builder for constructing complex q...

Data Integrity

Image
Introduction This is a term referring to the accuracy, completeness, consistency and reliability of data throughout its lifecycle, from when it is entered, stored, processed until it is deleted. Data with Integrity is data that correctly reflects objective reality and is not distorted, biased or contaminated due to system errors, human errors or hacker destruction. In database management systems like PostgreSQL, Data Integrity acts like strict rules, preventing any behavior that intentionally or unintentionally makes data absurd. To ensure data is always clean and correct, PostgreSQL provides the following core constraints: Entity Integrity When creating a table with a primary key, using a Unique Constraint or Unique Index means that the values in this column must be unique Ensures that the system can always distinguish between different entities, there is no such thing as two completely identical data rows or an "anonymous" data row existing. If you do not use the above meth...