Как стать автором
Обновить

Комментарии 4

Люблю NestJS. Декораторы кастомные не писал, спасибо за статью
Декораторы конечно штука хорошая, просто в какой-то момент обнаруживаешь что код декораторов занимает больше места, чем код классов…
Вот как-то так:
Декораторы на декораторах сидят, декораторами погоняют
@Crud({
  model: {
    type: User,
  },
  query: { alwaysPaginate: true },
  dto: { create: CreateUserRequestDto, update: UpdateUserRequestDto },
  serialize: { get: UserResponse, create: UserResponse, update: UserResponse },
  routes: {
    only: ['createOneBase', 'getOneBase', 'getManyBase', 'updateOneBase'],
    createOneBase: {
      decorators: [
        Roles('admin'),
        ApiBadRequestResponse(),
      ],
    },
    getOneBase: {
      decorators: [
        Roles('admin'),
        ApiBadRequestResponse(),
        ApiNotFoundResponse(),
      ],
    },
    getManyBase: {
      decorators: [
        Roles('admin'),
        ApiBadRequestResponse(),
        ApiNotFoundResponse(),
      ],
    },
    updateOneBase: {
      decorators: [
        Roles('admin'),
        ApiBadRequestResponse(),
        ApiNotFoundResponse(),
      ],
    },
  },
})
@ApiTags('user')
@UseGuards(RoleGuard)
@Controller('users')
export class UsersController implements CrudController<User> {
  constructor(public service: UsersService) {}
}

Зашло, как раз разбираюсь. Спасибо за статью.
НЛО прилетело и опубликовало эту надпись здесь
Зарегистрируйтесь на Хабре , чтобы оставить комментарий