import { Controller, UseGuards } from '@nestjs/common'; import { Crud, CrudController, Override, ParsedRequest, CrudRequest, } from '@nestjsx/crud'; import { StateCategory } from '../entities/state-category.entity'; import { StateCategoryDto } from './state-category.dto'; import { JwtAuthGuard } from 'src/auth/jwt-auth.guard'; import { ApiTags, ApiHeader, ApiBearerAuth } from '@nestjs/swagger'; import { StateCategoriesService } from './state-categories.service'; @ApiTags('State Categories') @ApiHeader({ name: 'Authorization', allowEmptyValue: false, description: '"Bearer Token"', example: 'Bearer ', }) @ApiBearerAuth() @Crud({ model: { type: StateCategory, }, routes: { exclude: ['replaceOneBase'], }, dto: { create: StateCategoryDto, update: StateCategoryDto, }, query: { filter: { deletedAt: { $eq: null, }, }, sort: [ { field: 'createdAt', order: 'ASC', }, ], }, serialize: { create: StateCategoryDto, createMany: StateCategoryDto, get: StateCategoryDto, getMany: StateCategoryDto, update: StateCategoryDto, replace: StateCategoryDto, }, }) @UseGuards(JwtAuthGuard) @Controller('state-categories') export class StateCategoriesController implements CrudController { constructor(public service: StateCategoriesService) {} get base(): CrudController { return this; } @Override() async deleteOne(@ParsedRequest() req: CrudRequest) { const id = req.parsed.paramsFilter.find( f => f.field === 'id' && f.operator === '$eq', ).value; const res = await this.service.markDeleted(id); return res; } }