From dbf19eb77a90530f249ad6ef169a3d87e6362b51 Mon Sep 17 00:00:00 2001 From: ilham Date: Thu, 16 Dec 2021 23:54:51 +0700 Subject: [PATCH 1/7] fix: product --- src/product/product-sub-categories.service.ts | 32 ++++++++++++++++++- src/product/product.controller.ts | 9 +++--- src/product/product.service.ts | 3 ++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/product/product-sub-categories.service.ts b/src/product/product-sub-categories.service.ts index 34e79a4..eb0aeab 100644 --- a/src/product/product-sub-categories.service.ts +++ b/src/product/product-sub-categories.service.ts @@ -44,10 +44,40 @@ export class ProductSubCategoriesService { ); } - findAll(page) { + async findAll(page, category) { + const baseQuery = this.productSubCategoriesRepository + .createQueryBuilder('product_sub_categories') + .leftJoinAndSelect( + 'product_sub_categories.category', + 'category', + ); + + if (category != 'null') { + baseQuery.where({ + category: category, + }); + } + + const data = await baseQuery + .skip(page * 10) + .take(10) + .getMany(); + + const totalData = await baseQuery.getCount(); + + return { + data, + count: totalData, + }; + } + + findAllByCategories(page, category) { return this.productSubCategoriesRepository.findAndCount({ skip: page * 10, take: 10, + where: { + category: category, + }, relations: ['category'], order: { version: 'DESC', diff --git a/src/product/product.controller.ts b/src/product/product.controller.ts index a3bea09..38aadc3 100644 --- a/src/product/product.controller.ts +++ b/src/product/product.controller.ts @@ -98,7 +98,7 @@ export class ProductController { @Get('by-categories-all') async findByCategoriesAll( @Query('page') page: number, - @Query('categories') categories: string, + @Query('sub-categories') categories: string, @Query('supplier') supplier: string, ) { const data = await this.productService.findAllBySubCategories( @@ -148,12 +148,11 @@ export class ProductController { } @Get('sub-categories') - async findAllSubCategories(@Query('page') page: number) { - const [data, count] = await this.productSubCategoriesService.findAll(page); + async findAllSubCategories(@Query('page') page: number,@Query('category') category: string) { + const data = await this.productSubCategoriesService.findAll(page, category); return { - data, - count, + ...data, statusCode: HttpStatus.OK, message: 'success', }; diff --git a/src/product/product.service.ts b/src/product/product.service.ts index 8e2980d..4e9c770 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -95,6 +95,9 @@ export class ProductService { } async findAllBySubCategories(page, subCategories, supplier) { + if (!supplier) { + supplier = await this.supplierService.findByActive(); + } const baseQuery = this.productRepository .createQueryBuilder('product') .leftJoin('product.sub_categories', 'sub_categories') From ba417b643eafbfc1ad6cb8473ba32c84144cee1f Mon Sep 17 00:00:00 2001 From: ilham Date: Fri, 17 Dec 2021 00:32:28 +0700 Subject: [PATCH 2/7] fix: product --- src/product/product-sub-categories.service.ts | 5 +---- src/product/product.controller.ts | 4 ++-- src/product/product.service.ts | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/product/product-sub-categories.service.ts b/src/product/product-sub-categories.service.ts index eb0aeab..c6c3b8c 100644 --- a/src/product/product-sub-categories.service.ts +++ b/src/product/product-sub-categories.service.ts @@ -47,10 +47,7 @@ export class ProductSubCategoriesService { async findAll(page, category) { const baseQuery = this.productSubCategoriesRepository .createQueryBuilder('product_sub_categories') - .leftJoinAndSelect( - 'product_sub_categories.category', - 'category', - ); + .leftJoinAndSelect('product_sub_categories.category', 'category'); if (category != 'null') { baseQuery.where({ diff --git a/src/product/product.controller.ts b/src/product/product.controller.ts index 38aadc3..312f8c2 100644 --- a/src/product/product.controller.ts +++ b/src/product/product.controller.ts @@ -98,12 +98,12 @@ export class ProductController { @Get('by-categories-all') async findByCategoriesAll( @Query('page') page: number, - @Query('sub-categories') categories: string, + @Query('sub-category') subcategory: string, @Query('supplier') supplier: string, ) { const data = await this.productService.findAllBySubCategories( page, - categories, + subcategory, supplier, ); diff --git a/src/product/product.service.ts b/src/product/product.service.ts index 4e9c770..4cebe51 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -95,19 +95,15 @@ export class ProductService { } async findAllBySubCategories(page, subCategories, supplier) { - if (!supplier) { + if (supplier != 'null' && !supplier) { supplier = await this.supplierService.findByActive(); } const baseQuery = this.productRepository .createQueryBuilder('product') .leftJoin('product.sub_categories', 'sub_categories') - .where( - 'sub_categories.category_id = :id and product.supplier_id = :supplier_id', - { - id: subCategories, - supplier_id: supplier, - }, - ) + .where('product.supplier_id = :supplier_id', { + supplier_id: supplier, + }) .leftJoinAndMapOne( 'product.currentPrice', 'product.priceHistory', @@ -115,6 +111,12 @@ export class ProductService { 'current_price.partner_id is null', ); + if (subCategories != 'null' && !subCategories) { + baseQuery.where('product.sub_categories_id = :id', { + id: subCategories, + }); + } + const data = await baseQuery .skip(page * 10) .take(10) From 8df907287abf2730ad4815fb3d9c7170a1674eb4 Mon Sep 17 00:00:00 2001 From: ilham Date: Fri, 17 Dec 2021 01:04:13 +0700 Subject: [PATCH 3/7] fix: get product --- src/product/product.service.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/product/product.service.ts b/src/product/product.service.ts index 4cebe51..da8e81a 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -15,6 +15,7 @@ import { productType } from '../helper/enum-list'; import { UpdatePriceProductDto } from './dto/product/update-price-product.dto'; import { UsersService } from '../users/users.service'; import { SupplierService } from '../users/supplier/supplier.service'; +import { type } from 'os'; export class ProductService { constructor( @@ -96,7 +97,7 @@ export class ProductService { async findAllBySubCategories(page, subCategories, supplier) { if (supplier != 'null' && !supplier) { - supplier = await this.supplierService.findByActive(); + supplier = (await this.supplierService.findByActive()).id; } const baseQuery = this.productRepository .createQueryBuilder('product') @@ -111,7 +112,8 @@ export class ProductService { 'current_price.partner_id is null', ); - if (subCategories != 'null' && !subCategories) { + if (subCategories != 'null' && subCategories) { + console.log(!subCategories,"testingan") baseQuery.where('product.sub_categories_id = :id', { id: subCategories, }); From 3c8b01893797365c3c7179d956992c8144787960 Mon Sep 17 00:00:00 2001 From: ilham Date: Fri, 17 Dec 2021 01:32:45 +0700 Subject: [PATCH 4/7] add: get product all --- src/product/product.controller.ts | 24 +++++++++++---- src/product/product.service.ts | 51 +++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/product/product.controller.ts b/src/product/product.controller.ts index 312f8c2..2a0ef46 100644 --- a/src/product/product.controller.ts +++ b/src/product/product.controller.ts @@ -69,13 +69,22 @@ export class ProductController { }; } - @Get() - async findAll(@Query('page') page: number) { - const [data, count] = await this.productService.findAll(page); + @Get('get-all') + async findAll( + @Query('page') page: number, + @Query('sub-category') subcategory: string, + @Query('category') category: string, + @Query('supplier') supplier: string, + ) { + const data = await this.productService.findAll( + page, + supplier, + category, + subcategory, + ); return { - data, - count, + ...data, statusCode: HttpStatus.OK, message: 'success', }; @@ -148,7 +157,10 @@ export class ProductController { } @Get('sub-categories') - async findAllSubCategories(@Query('page') page: number,@Query('category') category: string) { + async findAllSubCategories( + @Query('page') page: number, + @Query('category') category: string, + ) { const data = await this.productSubCategoriesService.findAll(page, category); return { diff --git a/src/product/product.service.ts b/src/product/product.service.ts index da8e81a..daef8a0 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -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, }); From c5b5a4ab0662319f453d345a1e22fc06af58de2e Mon Sep 17 00:00:00 2001 From: ilham Date: Fri, 17 Dec 2021 01:46:22 +0700 Subject: [PATCH 5/7] fix: change wording on error --- src/configurable/commission.service.ts | 4 ++-- src/product/history-price/history-price.service.ts | 2 +- src/product/product-categories.service.ts | 8 ++++---- src/product/product-sub-categories.service.ts | 8 ++++---- src/product/product.service.ts | 6 +++--- src/transaction/coa.service.ts | 2 +- src/users/supplier/supplier.service.ts | 2 +- src/users/users.service.ts | 12 ++++++------ 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/configurable/commission.service.ts b/src/configurable/commission.service.ts index 491e929..4b605a4 100644 --- a/src/configurable/commission.service.ts +++ b/src/configurable/commission.service.ts @@ -34,7 +34,7 @@ export class CommissionService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Commission not found', }, HttpStatus.NOT_FOUND, ); @@ -52,7 +52,7 @@ export class CommissionService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Commission not found', }, HttpStatus.NOT_FOUND, ); diff --git a/src/product/history-price/history-price.service.ts b/src/product/history-price/history-price.service.ts index eb0a183..77e71bb 100644 --- a/src/product/history-price/history-price.service.ts +++ b/src/product/history-price/history-price.service.ts @@ -25,7 +25,7 @@ export class ProductHistoryPriceService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Price not found', }, HttpStatus.NOT_FOUND, ); diff --git a/src/product/product-categories.service.ts b/src/product/product-categories.service.ts index d3c2cdc..6aa1e30 100644 --- a/src/product/product-categories.service.ts +++ b/src/product/product-categories.service.ts @@ -54,7 +54,7 @@ export class ProductCategoriesService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Product Categories not found', }, HttpStatus.NOT_FOUND, ); @@ -76,7 +76,7 @@ export class ProductCategoriesService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Product Categories not found', }, HttpStatus.NOT_FOUND, ); @@ -97,7 +97,7 @@ export class ProductCategoriesService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Product Categories not found', }, HttpStatus.NOT_FOUND, ); @@ -122,7 +122,7 @@ export class ProductCategoriesService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Product Categories not found', }, HttpStatus.NOT_FOUND, ); diff --git a/src/product/product-sub-categories.service.ts b/src/product/product-sub-categories.service.ts index c6c3b8c..ffc0492 100644 --- a/src/product/product-sub-categories.service.ts +++ b/src/product/product-sub-categories.service.ts @@ -49,7 +49,7 @@ export class ProductSubCategoriesService { .createQueryBuilder('product_sub_categories') .leftJoinAndSelect('product_sub_categories.category', 'category'); - if (category != 'null') { + if (category != 'null' && category) { baseQuery.where({ category: category, }); @@ -90,7 +90,7 @@ export class ProductSubCategoriesService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Product Sub Categories not found', }, HttpStatus.NOT_FOUND, ); @@ -111,7 +111,7 @@ export class ProductSubCategoriesService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Product Sub Categories not found', }, HttpStatus.NOT_FOUND, ); @@ -140,7 +140,7 @@ export class ProductSubCategoriesService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Product Sub Categories not found', }, HttpStatus.NOT_FOUND, ); diff --git a/src/product/product.service.ts b/src/product/product.service.ts index daef8a0..f459374 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -216,7 +216,7 @@ export class ProductService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Product not found', }, HttpStatus.NOT_FOUND, ); @@ -234,7 +234,7 @@ export class ProductService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Product not found', }, HttpStatus.NOT_FOUND, ); @@ -283,7 +283,7 @@ export class ProductService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Product not found', }, HttpStatus.NOT_FOUND, ); diff --git a/src/transaction/coa.service.ts b/src/transaction/coa.service.ts index 33beffc..fac2a6e 100644 --- a/src/transaction/coa.service.ts +++ b/src/transaction/coa.service.ts @@ -66,7 +66,7 @@ export class CoaService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'COA not found', }, HttpStatus.NOT_FOUND, ); diff --git a/src/users/supplier/supplier.service.ts b/src/users/supplier/supplier.service.ts index 7a5155e..68bef24 100644 --- a/src/users/supplier/supplier.service.ts +++ b/src/users/supplier/supplier.service.ts @@ -164,7 +164,7 @@ export class SupplierService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'Supplier not found', }, HttpStatus.NOT_FOUND, ); diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 4235e3f..38fb9e9 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -205,7 +205,7 @@ export class UsersService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'User not found', }, HttpStatus.NOT_FOUND, ); @@ -228,7 +228,7 @@ export class UsersService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'User not found', }, HttpStatus.NOT_FOUND, ); @@ -258,7 +258,7 @@ export class UsersService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'User not found', }, HttpStatus.NOT_FOUND, ); @@ -276,7 +276,7 @@ export class UsersService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'User not found', }, HttpStatus.NOT_FOUND, ); @@ -337,7 +337,7 @@ export class UsersService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'User not found', }, HttpStatus.NOT_FOUND, ); @@ -371,7 +371,7 @@ export class UsersService { throw new HttpException( { statusCode: HttpStatus.NOT_FOUND, - error: 'Data not found', + error: 'User not found', }, HttpStatus.NOT_FOUND, ); From 4d1ac8dd0d9ed948e72667d05d2c0ff0e6e529e7 Mon Sep 17 00:00:00 2001 From: caturbgs Date: Fri, 17 Dec 2021 01:57:02 +0700 Subject: [PATCH 6/7] feat: change url name --- src/product/product.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/product/product.controller.ts b/src/product/product.controller.ts index 2a0ef46..058cf15 100644 --- a/src/product/product.controller.ts +++ b/src/product/product.controller.ts @@ -69,7 +69,7 @@ export class ProductController { }; } - @Get('get-all') + @Get('all') async findAll( @Query('page') page: number, @Query('sub-category') subcategory: string, From 5da48273c0afda9337e4bdb139fa573fcef00b8b Mon Sep 17 00:00:00 2001 From: ilham Date: Fri, 17 Dec 2021 02:00:07 +0700 Subject: [PATCH 7/7] fix: get product all --- src/product/product.controller.ts | 20 +------------------- src/product/product.service.ts | 2 +- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/product/product.controller.ts b/src/product/product.controller.ts index 2a0ef46..08f09ce 100644 --- a/src/product/product.controller.ts +++ b/src/product/product.controller.ts @@ -69,7 +69,7 @@ export class ProductController { }; } - @Get('get-all') + @Get('all') async findAll( @Query('page') page: number, @Query('sub-category') subcategory: string, @@ -179,24 +179,6 @@ export class ProductController { }; } - @Get('categories/:id') - async findOneCategories(@Param('id', ParseUUIDPipe) id: string) { - return { - data: await this.productCategoriesService.findOne(id), - statusCode: HttpStatus.OK, - message: 'success', - }; - } - - @Get('sub-categories/:id') - async findOneSubCategories(@Param('id', ParseUUIDPipe) id: string) { - return { - data: await this.productSubCategoriesService.findOne(id), - statusCode: HttpStatus.OK, - message: 'success', - }; - } - @Put(':id') async update( @Param('id', ParseUUIDPipe) id: string, diff --git a/src/product/product.service.ts b/src/product/product.service.ts index f459374..57f96dc 100644 --- a/src/product/product.service.ts +++ b/src/product/product.service.ts @@ -54,7 +54,7 @@ export class ProductService { } async findAll(page, supplier, categories, subCategories) { - if (supplier != 'null' && !supplier) { + if (supplier == 'null' || !supplier) { supplier = (await this.supplierService.findByActive()).id; } const baseQuery = this.productRepository