inventario
This commit is contained in:
70
apps/api/src/features/inventory/inventory.controller.ts
Normal file
70
apps/api/src/features/inventory/inventory.controller.ts
Normal 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);
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user