- Introduced `ProductsModule` to manage product data, including read and write controllers. - Created database migrations for the `products`, `sales_requests`, `sales_orders`, `sales_invoices`, and related tables, including constraints and unique indexes. - Implemented validation for product fields such as code, name, unit, and brand with corresponding utility functions. - Developed service and repository layers for handling product and sales data operations. - Added unit tests for the products and sales services, repositories, and controllers to ensure functionality and correctness. - Updated application module to include the new `ProductsModule` and related sales modules for better organization.
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { Controller, Get, Param, ParseUUIDPipe, Query } from '@nestjs/common';
|
|
import {
|
|
ApiBearerAuth,
|
|
ApiForbiddenResponse,
|
|
ApiNotFoundResponse,
|
|
ApiOkResponse,
|
|
ApiOperation,
|
|
ApiTags,
|
|
ApiUnauthorizedResponse,
|
|
} from '@nestjs/swagger';
|
|
import { RequirePrivilege } from '../../../common/decorators/require-privilege.decorator';
|
|
import {
|
|
Pagination,
|
|
type PaginationResponse,
|
|
PaginationMetaDto,
|
|
} from '../../../common/http/response';
|
|
import { BEARER_AUTH_NAME } from '../../../common/swagger/setup-swagger';
|
|
import { ProductDto, ListProductsQueryDto } from './dto/product.dto';
|
|
import { ProductsService } from './products.service';
|
|
|
|
export const PRODUCT_PRIVILEGE_KEY = 'CONFIGURATION.PRODUCT';
|
|
|
|
@ApiTags('products')
|
|
@ApiBearerAuth(BEARER_AUTH_NAME)
|
|
@Controller('products')
|
|
export class ProductsReadController {
|
|
constructor(private readonly productsService: ProductsService) {}
|
|
|
|
@Get()
|
|
@Pagination()
|
|
@RequirePrivilege(PRODUCT_PRIVILEGE_KEY, 'view')
|
|
@ApiOperation({ summary: 'List products' })
|
|
@ApiOkResponse({
|
|
schema: {
|
|
properties: {
|
|
data: {
|
|
type: 'array',
|
|
items: { $ref: '#/components/schemas/ProductDto' },
|
|
},
|
|
meta: { $ref: '#/components/schemas/PaginationMetaDto' },
|
|
},
|
|
},
|
|
})
|
|
@ApiUnauthorizedResponse()
|
|
@ApiForbiddenResponse()
|
|
list(
|
|
@Query() query: ListProductsQueryDto,
|
|
): Promise<PaginationResponse<ProductDto>> {
|
|
return this.productsService.list(query);
|
|
}
|
|
|
|
@Get(':id')
|
|
@RequirePrivilege(PRODUCT_PRIVILEGE_KEY, 'view')
|
|
@ApiOperation({ summary: 'Get product detail' })
|
|
@ApiOkResponse({ type: ProductDto })
|
|
@ApiNotFoundResponse()
|
|
@ApiUnauthorizedResponse()
|
|
@ApiForbiddenResponse()
|
|
findOne(@Param('id', ParseUUIDPipe) id: string): Promise<ProductDto> {
|
|
return this.productsService.findById(id);
|
|
}
|
|
}
|
|
|
|
void PaginationMetaDto;
|