Комментарии 4
Люблю NestJS. Декораторы кастомные не писал, спасибо за статью
+3
Декораторы конечно штука хорошая, просто в какой-то момент обнаруживаешь что код декораторов занимает больше места, чем код классов…
Вот как-то так:
Вот как-то так:
Декораторы на декораторах сидят, декораторами погоняют
@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) {}
}
+1
Зашло, как раз разбираюсь. Спасибо за статью.
+2
НЛО прилетело и опубликовало эту надпись здесь
Зарегистрируйтесь на Хабре , чтобы оставить комментарий
Кастомные декораторы для NestJS: от простого к сложному