1.1

After the initial full release of the course, many more ideas of refactors and improvements arose, apart from dependency version updates (mainly Nest v9 to v10). Due to the big amount of changes, I decided to call this the 1.1 update. Changes are as follows:

Core module

  • Update packages with ncu (Nest v9 -> v10)

  • Update project's base files as according to Nest v10 template

  • Improvements in basic project configuration

    • No more need to struggle with EoL (Nest CLI generates line breaks accordingly to OS)

    • ESLint file back to JS (more versatile)

    • In Prettier file, enable organize-imports plugin and use EoL as auto

  • More explicit about creating folder domain/users during first steps

  • Insomnia (updated)

    • How to create first request

    • Access base environment

    • Access folder env

    • Improvement: better setup of path parameters

  • Update Docker compose file

    • Remove version (obsolete)

    • Named volume for database

  • More explicit about using migrations with npm

  • .env.example with sample data (easier to understand & avoids need for defaults)

  • Use port() in env validation schema

  • Use ConfigService in main file (environment variable for APP_PORT)

  • Generate the database url inside codebase (better for deploy)

  • Validate uniqueness of arrays with @ArrayUnique()

    • Identifier functions for arrays of objects

  • New lesson: function overload for wrapping ids

  • Fix: add @IsDefined() to @IsEntity()

  • Use simplified transaction syntax

Improvements/Tips

  • Rename some files for simplicity

    • Folder text-validation with just text

    • Validators at-least-one... with contains...

  • New lesson: More validations

    • Max value for id - postgres integer (32-bit)

    • User name with letters and spaces (no consecutive, leading or trailing)

Authentication/Authorization

  • Define LoginDto as PickType of CreateUserDto (alternative)

  • Fix: use flatMap() in middleware instead of join() (for many constraints)

  • New lesson: generic middleware

  • Better explanation about JWT cookie options

  • Explanations about different forms of setting route metadata

    • Alternative definition of Public decorator (directly receive SetMetadata())

    • Alternative definition of Roles decorator (Reflector.createDecorator())

  • Updates to throttler

    • Use helper instead of directly converting to ms

    • Use as const in array instead of inner object

    • Explanation about it not working in login() route (due to middleware)

    • Fix: relocate ThrottlerGuard as first guard

Exception Filters

  • Remove extractFromText() function and use regexes with lookbehind (ES2018)

  • Use switch(true) to avoid using if-else cascades

OpenAPI Specification

  • Use documentFactory when generating the document

  • Remove @ApiTags() decorators (no longer necessary)

  • Replace HeadersObject type in cookie header with more "high-level" type

  • New lesson: append decorators during system startup with DiscoveryService

File Management

  • Type alias for Express.Multer.File

  • New type FileSizeMagnitude when validating file size

  • Transaction for deleting product and its base directory

  • New lesson: make products' images available through serve static

  • Better type safety when catching SyntaxError inside BodyInterceptor

  • Update files exception filter to use lookbehind regexes and switch(true)

Advanced Querying

  • New lesson: Document paginated responses

  • Rename DTOs such as ProductsFilterDto to FilterProductsDto (like CreateProductDto, maintain this pattern)

  • Explanation about replacing enums with const arrays

  • Better type for Sort array, enforcing Product fields

  • Showcase of TypeScript new autocomplete for switch case

  • Improved algorithm for toFilterOperationDto()

Automated Testing

  • Add paths of jest config files to ignorePatterns in ESLint file

  • Improvements to testing utilities

    • MockRepository actually requires entity type for signature inference

    • Single function to encapsulate mock() (variable already typed)

  • Use parameter default in genUser() function

  • Change server type to Server (HttpServer not accepted anymore by request())

  • Fix: script to remove test database now also removes the volume

  • Use .env file for testing

  • Use chainable matcher instead of expect.objectContaining()

  • Remove spread of createUserDto from inside updateUserDto (no longer necessary)

  • Use hardcoded phone in e2e test (due to updated validation in class validator)

  • Type assert the body in response for better type safety

Other changes

  • Easier command to use node lts version with nvm

  • Explanation about formatting project to replace all LF line breaks with CRLF (Windows)

  • Update phone in Insomnia (new class-validator validation)

  • Pluralize DefaultPageSize elements

  • Inline JSDocs

  • Rename database credentials in .env

  • No more need to put .env file in .gitignore manually

  • In reduce() lambda expression, rename parameters to be more expressive

  • Correction in commit name for validating booleans

  • Remove LF lesson (no longer necessary)

  • Link in complementary material about Request lifecycle (execution order of enhancers)

  • Remove generics when obtaining references from within modules in tests (optional)

  • Remove General Refactors section, and integrate refactors in respective lessons

Last updated