status añadido, cambios en el responsive al ver el producto
This commit is contained in:
@@ -32,10 +32,17 @@ export class CreateProductDto {
|
||||
address: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsInt({
|
||||
message: 'stock must be a number',
|
||||
@IsString({
|
||||
message: 'address must be a string',
|
||||
})
|
||||
@IsOptional()
|
||||
status: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsInt({
|
||||
message: 'userID must be a number',
|
||||
})
|
||||
// @IsOptional()
|
||||
userId: number;
|
||||
|
||||
@ApiProperty()
|
||||
|
||||
@@ -20,6 +20,9 @@ export class UpdateProductDto extends PartialType(CreateProductDto) {
|
||||
@IsOptional()
|
||||
address: string;
|
||||
|
||||
@IsOptional()
|
||||
status: string;
|
||||
|
||||
@IsOptional()
|
||||
urlImg: string;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export class UsersController {
|
||||
@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);
|
||||
const result = await this.inventoryService.findAll(paginationDto,true);
|
||||
return {
|
||||
message: 'products fetched successfully',
|
||||
data: result.data,
|
||||
|
||||
@@ -56,6 +56,7 @@ export class InventoryService {
|
||||
address: products.address,
|
||||
price: products.price,
|
||||
stock: products.stock,
|
||||
status: products.status,
|
||||
urlImg: products.urlImg
|
||||
})
|
||||
.from(products)
|
||||
@@ -78,7 +79,7 @@ export class InventoryService {
|
||||
return { data, meta };
|
||||
}
|
||||
|
||||
async findAll(paginationDto?: PaginationDto): Promise<{ data: Store[], meta: any }> {
|
||||
async findAll(paginationDto?: PaginationDto, isStore: boolean = false): Promise<{ data: Store[], meta: any }> {
|
||||
const { page = 1, limit = 10, search = '', sortBy = 'id', sortOrder = 'asc' } = paginationDto || {};
|
||||
|
||||
// Calculate offset
|
||||
@@ -86,11 +87,21 @@ export class InventoryService {
|
||||
|
||||
// Build search condition
|
||||
let searchCondition: SQL<unknown> | undefined;
|
||||
if (search) {
|
||||
searchCondition = or(
|
||||
if (search && isStore) {
|
||||
searchCondition = and(
|
||||
or(
|
||||
like(viewProductsStore.title, `%${search}%`),
|
||||
like(viewProductsStore.description, `%${search}%`)
|
||||
),
|
||||
or(eq(viewProductsStore.status, 'PUBLICADO'), eq(viewProductsStore.status, 'AGOTADO'))
|
||||
)
|
||||
} else if(search){
|
||||
or(
|
||||
like(viewProductsStore.title, `%${search}%`),
|
||||
like(viewProductsStore.description, `%${search}%`),
|
||||
);
|
||||
like(viewProductsStore.description, `%${search}%`)
|
||||
)
|
||||
} else if(isStore){
|
||||
searchCondition = or(eq(viewProductsStore.status, 'PUBLICADO'), eq(viewProductsStore.status, 'AGOTADO'))
|
||||
}
|
||||
|
||||
// Build sort condition
|
||||
@@ -117,6 +128,7 @@ export class InventoryService {
|
||||
address: viewProductsStore.address,
|
||||
urlImg: viewProductsStore.urlImg,
|
||||
stock: viewProductsStore.stock,
|
||||
status: viewProductsStore.status,
|
||||
userId: viewProductsStore.userId,
|
||||
fullname: viewProductsStore.fullname,
|
||||
email: viewProductsStore.email,
|
||||
@@ -152,6 +164,7 @@ export class InventoryService {
|
||||
address: viewProductsStore.address,
|
||||
urlImg: viewProductsStore.urlImg,
|
||||
stock: viewProductsStore.stock,
|
||||
status: viewProductsStore.status,
|
||||
userId: viewProductsStore.userId,
|
||||
fullname: viewProductsStore.fullname,
|
||||
email: viewProductsStore.email,
|
||||
@@ -185,6 +198,7 @@ export class InventoryService {
|
||||
address: createProductDto.address,
|
||||
urlImg: createProductDto.urlImg,
|
||||
stock: createProductDto.stock,
|
||||
status: createProductDto.status,
|
||||
userId: createProductDto.userId
|
||||
})
|
||||
.returning();
|
||||
@@ -194,7 +208,8 @@ export class InventoryService {
|
||||
|
||||
async update(id: string, updateProductDto: UpdateProductDto): Promise<Product> {
|
||||
const productId = parseInt(id);
|
||||
|
||||
console.log(updateProductDto);
|
||||
|
||||
// Check if exists
|
||||
await this.findOne(id);
|
||||
|
||||
@@ -204,6 +219,7 @@ export class InventoryService {
|
||||
if (updateProductDto.description) updateData.description = updateProductDto.description;
|
||||
if (updateProductDto.price) updateData.price = updateProductDto.price;
|
||||
if (updateProductDto.address) updateData.address = updateProductDto.address;
|
||||
if (updateProductDto.status) updateData.status = updateProductDto.status;
|
||||
if (updateProductDto.stock) updateData.stock = updateProductDto.stock;
|
||||
if (updateProductDto.urlImg) updateData.urlImg = updateProductDto.urlImg;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user