ver productos y detalles

This commit is contained in:
2025-07-09 14:56:58 -04:00
parent 365cbd0d7a
commit 3a0b29d3c1
14 changed files with 144 additions and 91 deletions

View File

@@ -6,6 +6,7 @@ export class Product {
stock: number | null;
urlImg: string | null;
userId?: number | null;
fullname?: string | null;
}
export class Inventory {

View File

@@ -30,8 +30,8 @@ export class UsersController {
@ApiResponse({ status: 200, description: 'Return paginated products.' })
async findAllByUserId(@Req() req: Request, @Query() paginationDto: PaginationDto) {
console.log(req['user'].id)
const id = 1
// const id = Number(req['user'].id);
// const id = 1
const id = Number(req['user'].id);
const result = await this.inventoryService.findAllByUserId(id,paginationDto);
return {
message: 'products fetched successfully',
@@ -40,7 +40,7 @@ export class UsersController {
};
}
@Get(':id')
@Get('/id/:id')
// @Roles('admin')
@ApiOperation({ summary: 'Get a product by ID' })
@ApiResponse({ status: 200, description: 'Return the product.' })

View File

@@ -141,15 +141,17 @@ export class InventoryService {
async findOne(id: string): Promise<Product> {
const find = await this.drizzle
.select({
id: products.id,
title: products.title,
description: products.description,
price: products.price,
urlImg: products.urlImg,
stock: products.stock
id: viewProductsStore.id,
title: viewProductsStore.title,
description: viewProductsStore.description,
price: viewProductsStore.price,
urlImg: viewProductsStore.urlImg,
stock: viewProductsStore.stock,
userId: viewProductsStore.userId,
fullname: viewProductsStore.fullname
})
.from(products)
.where(eq(products.id, parseInt(id)));
.from(viewProductsStore)
.where(eq(viewProductsStore.id, parseInt(id)));
if (find.length === 0) {
throw new HttpException('Product does not exist', HttpStatus.BAD_REQUEST);

View File

@@ -40,12 +40,11 @@ export class UsersController {
@ApiResponse({ status: 201, description: 'User created successfully.' })
async create(
@Body() createUserDto: CreateUserDto,
@Query('roleId') roleId?: string,
@Query('role') role?: string,
) {
const data = await this.usersService.create(
createUserDto,
roleId ? parseInt(roleId) : undefined,
);
console.log(role);
const data = await this.usersService.create(createUserDto)
return { message: 'User created successfully', data };
}

View File

@@ -159,7 +159,7 @@ export class UsersService {
// Assign role to user
await tx.insert(usersRole).values({
userId: newUser.id,
roleId: roleId,
roleId: createUserDto.role || roleId,
});
// Return the created user with role