inventario

This commit is contained in:
2025-06-20 12:56:47 -04:00
parent f87f235967
commit 0a65946a8a
11 changed files with 403 additions and 3 deletions

View File

@@ -0,0 +1,70 @@
import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from '@nestjs/common';
import { InventoryService } from './inventory.service';
import { CreateProductDto } from './dto/create-product.dto';
import { UpdateProductDto } from './dto/update-product.dto';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Roles } from '../../common/decorators/roles.decorator';
import { PaginationDto } from '../../common/dto/pagination.dto';
@ApiTags('inventory')
@Controller('inventory')
export class UsersController {
constructor(private readonly inventoryService: InventoryService) {}
@Get()
// @Roles('admin')
@ApiOperation({ summary: 'Get all products with pagination and filters' })
@ApiResponse({ status: 200, description: 'Return paginated products.' })
async findAll(@Query() paginationDto: PaginationDto) {
const result = await this.inventoryService.findAll(paginationDto);
return {
message: 'products fetched successfully',
data: result.data,
meta: result.meta
};
}
@Get(':id')
// @Roles('admin')
@ApiOperation({ summary: 'Get a product by ID' })
@ApiResponse({ status: 200, description: 'Return the product.' })
@ApiResponse({ status: 404, description: 'product not found.' })
async findOne(@Param('id') id: string) {
const data = await this.inventoryService.findOne(id);
return { message: 'product fetched successfully', data };
}
@Post()
// @Roles('admin')
@ApiOperation({ summary: 'Create a new product' })
@ApiResponse({ status: 201, description: 'Product created successfully.' })
async create(
@Body() createUserDto: CreateProductDto,
@Query('roleId') roleId?: string,
) {
const data = await this.inventoryService.create(
createUserDto,
roleId ? parseInt(roleId) : undefined,
);
return { message: 'User created successfully', data };
}
// @Patch(':id')
// @Roles('admin')
// @ApiOperation({ summary: 'Update a user' })
// @ApiResponse({ status: 200, description: 'User updated successfully.' })
// @ApiResponse({ status: 404, description: 'User not found.' })
// async update(@Param('id') id: string, @Body() UpdateProductDto: UpdateProductDto) {
// const data = await this.inventoryService.update(id, UpdateProductDto);
// return { message: 'User updated successfully', data };
// }
// @Delete(':id')
// @Roles('admin')
// @ApiOperation({ summary: 'Delete a user' })
// @ApiResponse({ status: 200, description: 'User deleted successfully.' })
// @ApiResponse({ status: 404, description: 'User not found.' })
// async remove(@Param('id') id: string) {
// return await this.inventoryService.remove(id);
// }
}