AIT Template - BoilerPlate Service

BoilerPlate service for AIT Template microservice.

Table of Contents

General Information

  • Backend uses microservices architecture with NestJS as primary framework

Technologies Used

  • NestJS - version 14.17.0-alpine
  • PostgreSQL
  • JSON Web Token for auth

Setup

  • Copy .env.example to .env and fill in the parameters
  • yarn install
  • yarn start:dev

Use

Auth

  • @UserType is used to identify the user type, you can fill more than one by using ","

    @Get('my-profile')
    @UserType('admin', 'mechant')
    @AuthJwtGuard()
    @ResponseStatusCode()
    async myProfile(@User() user: IUser) {
      const profile = await this.profileService.findOne(user.id);
      return this.responseService.success(profile);
    }
  • @UserTypeAndLevel is used to identify the user type and level, you can fill more than one by using ","

    @Get('my-profile')
    @UserTypeAndLevel('admin.*', 'mechant.store')
    @AuthJwtGuard()
    @ResponseStatusCode()
    async myProfile(@User() user: IUser) {
      const profile = await this.profileService.findOne(user.id);
      return this.responseService.success(profile);
    }
  • @Permission is used to limit who has this permission

    @Get('my-profile')
    @Permission('profile.read')
    @AuthJwtGuard()
    @ResponseStatusCode()
    async myProfile(@User() user: IUser) {
      const profile = await this.profileService.findOne(user.id);
      return this.responseService.success(profile);
    }
  • @User is used to get User data from access token

    @Get('my-profile')
    @Permission('profile.read')
    @AuthJwtGuard()
    @ResponseStatusCode()
    async myProfile(@User() user: IUser) {
      const profile = await this.profileService.findOne(user.id);
      return this.responseService.success(profile);
    }