@nest-extended/decorators

Small, reusable decorators that standardise controller behaviour — reading the current user, marking routes public, and transforming the request body.

$npm install @nest-extended/decorators

Key exports

ExportTypePurpose
@User()param decoratorInject the authenticated req.user
@Public()method decoratorMark a route public (skip the auth guard)
@ModifyBody(...fns)param decoratorTransform the request body before it reaches the handler
setCreatedBy(key?)modifierStamp the current user id onto a body field (createdBy by default)
IS_PUBLIC_KEYconstMetadata key used by @Public()

Usage

cats.controller.ts
import { Controller, Get, Post, Patch, Param } from '@nestjs/common';
import { User, Public, ModifyBody, setCreatedBy } from '@nest-extended/decorators';
 
@Controller('cats')
export class CatsController {
  @Public()
  @Get()
  findAll() {
    // no JWT required
  }
 
  @Post()
  create(@ModifyBody(setCreatedBy()) body: CreateCatDto) {
    // body.createdBy === current user id
  }
 
  @Patch(':id')
  update(@Param('id') id: string, @ModifyBody(setCreatedBy('updatedBy')) body: UpdateCatDto) {
    // body.updatedBy === current user id
  }
 
  @Get('me')
  profile(@User() user: AuthenticatedUser) {
    return user;
  }
}

@ModifyBody accepts multiple modifier functions and runs them in order, so you can compose your own transforms alongside setCreatedBy.

Next steps