add: get product all
This commit is contained in:
@@ -53,15 +53,47 @@ export class ProductService {
|
||||
return this.productRepository.findOneOrFail(result.identifiers[0].id);
|
||||
}
|
||||
|
||||
findAll(page) {
|
||||
return this.productRepository.findAndCount({
|
||||
skip: page * 10,
|
||||
relations: ['sub_categories'],
|
||||
take: 10,
|
||||
order: {
|
||||
version: 'DESC',
|
||||
},
|
||||
});
|
||||
async findAll(page, supplier, categories, subCategories) {
|
||||
if (supplier != 'null' && !supplier) {
|
||||
supplier = (await this.supplierService.findByActive()).id;
|
||||
}
|
||||
const baseQuery = this.productRepository
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
.leftJoin('sub_categories.category', 'category')
|
||||
.where('product.supplier_id = :supplier_id', {
|
||||
supplier_id: supplier,
|
||||
})
|
||||
.leftJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.partner_id is null',
|
||||
);
|
||||
|
||||
if (subCategories != 'null' && subCategories) {
|
||||
baseQuery.where('product.sub_categories_id = :id', {
|
||||
id: subCategories,
|
||||
});
|
||||
}
|
||||
|
||||
if (categories != 'null' && categories) {
|
||||
baseQuery.where('sub_categories.category_id = :id', {
|
||||
id: categories,
|
||||
});
|
||||
}
|
||||
|
||||
const data = await baseQuery
|
||||
.skip(page * 10)
|
||||
.take(10)
|
||||
.getMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
|
||||
return {
|
||||
data,
|
||||
count: totalData,
|
||||
};
|
||||
}
|
||||
|
||||
async findAllByCategories(page, subCategories, supplier) {
|
||||
@@ -113,7 +145,6 @@ export class ProductService {
|
||||
);
|
||||
|
||||
if (subCategories != 'null' && subCategories) {
|
||||
console.log(!subCategories,"testingan")
|
||||
baseQuery.where('product.sub_categories_id = :id', {
|
||||
id: subCategories,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user