73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Patch,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
import { PermissionCode } from '../authorization/enums/permission-code.enum';
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
import { Permissions } from '../auth/decorators/permissions.decorator';
|
|
import { Roles } from '../auth/decorators/roles.decorator';
|
|
import { PermissionsGuard } from '../auth/guards/permissions.guard';
|
|
import { RolesGuard } from '../auth/guards/roles.guard';
|
|
import { AuthUser } from '../auth/interfaces/auth-user.interface';
|
|
import { UserRole } from '../users/enums/user-role.enum';
|
|
import { CustomersService } from './customers.service';
|
|
import { UpdateCustomerDto } from './dto/update-customer.dto';
|
|
import { SWAGGER_JWT_AUTH } from '../swagger/swagger.setup';
|
|
import {
|
|
ApiStandardController,
|
|
ApiStandardEmptyResponse,
|
|
ApiStandardOkResponse,
|
|
} from '../swagger/decorators/swagger-response.decorator';
|
|
import { Customer } from './entities/customer.entity';
|
|
|
|
@ApiTags('Customers')
|
|
@ApiBearerAuth(SWAGGER_JWT_AUTH)
|
|
@ApiStandardController()
|
|
@Controller('customers')
|
|
@UseGuards(RolesGuard, PermissionsGuard)
|
|
export class CustomersController {
|
|
constructor(private readonly customersService: CustomersService) {}
|
|
|
|
@Roles(UserRole.ADMIN)
|
|
@Permissions(PermissionCode.CUSTOMERS_READ)
|
|
@ApiStandardOkResponse(Customer, { isArray: true })
|
|
@Get()
|
|
findAll() {
|
|
return this.customersService.findAll();
|
|
}
|
|
|
|
@ApiStandardOkResponse(Customer)
|
|
@Get(':id')
|
|
findOne(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.customersService.findOne(id, user);
|
|
}
|
|
|
|
@ApiStandardOkResponse(Customer)
|
|
@Patch(':id')
|
|
update(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() updateCustomerDto: UpdateCustomerDto,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.customersService.update(id, updateCustomerDto, user);
|
|
}
|
|
|
|
@Roles(UserRole.ADMIN)
|
|
@Permissions(PermissionCode.CUSTOMERS_DELETE)
|
|
@ApiStandardEmptyResponse()
|
|
@Delete(':id')
|
|
remove(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.customersService.remove(id);
|
|
}
|
|
}
|