ver productos y detalles
This commit is contained in:
@@ -25,8 +25,10 @@ export const viewProductsStore = t.pgView('v_product_store', {
|
||||
stock: t.integer('stock'),
|
||||
urlImg: t.text('url_img'),
|
||||
userId: t.integer('user_id'),
|
||||
fullname: t.text('fullname')
|
||||
fullname: t.text('fullname'),
|
||||
email: t.text('email'),
|
||||
phone: t.text('phone')
|
||||
}).as(sql`
|
||||
select p.id as product_id, p.title, p.description, p.price, p.stock, p.url_img, p.user_id, u.fullname
|
||||
select p.id as product_id, p.title, p.description, p.price, p.stock, p.url_img, p.user_id, u.fullname, u.email, u.phone
|
||||
from products p
|
||||
left join auth.users as u on u.id = p.user_id`);
|
||||
@@ -6,6 +6,7 @@ export class Product {
|
||||
stock: number | null;
|
||||
urlImg: string | null;
|
||||
userId?: number | null;
|
||||
fullname?: string | null;
|
||||
}
|
||||
|
||||
export class Inventory {
|
||||
|
||||
@@ -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.' })
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user