Merge branch 'development' into 'devops-staging'

Development

See merge request empatnusabangsa/ppob/ppob-backend!33
This commit is contained in:
ilham dwi pratama 2021-12-16 19:01:44 +00:00
commit 051ae989e4
9 changed files with 125 additions and 67 deletions

View File

@ -34,7 +34,7 @@ export class CommissionService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Commission not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -52,7 +52,7 @@ export class CommissionService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Commission not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );

View File

@ -25,7 +25,7 @@ export class ProductHistoryPriceService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Price not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );

View File

@ -54,7 +54,7 @@ export class ProductCategoriesService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Product Categories not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -76,7 +76,7 @@ export class ProductCategoriesService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Product Categories not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -97,7 +97,7 @@ export class ProductCategoriesService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Product Categories not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -122,7 +122,7 @@ export class ProductCategoriesService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Product Categories not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );

View File

@ -44,10 +44,37 @@ 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' && category) {
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({ return this.productSubCategoriesRepository.findAndCount({
skip: page * 10, skip: page * 10,
take: 10, take: 10,
where: {
category: category,
},
relations: ['category'], relations: ['category'],
order: { order: {
version: 'DESC', version: 'DESC',
@ -63,7 +90,7 @@ export class ProductSubCategoriesService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Product Sub Categories not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -84,7 +111,7 @@ export class ProductSubCategoriesService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Product Sub Categories not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -113,7 +140,7 @@ export class ProductSubCategoriesService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Product Sub Categories not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );

View File

@ -69,13 +69,22 @@ export class ProductController {
}; };
} }
@Get() @Get('all')
async findAll(@Query('page') page: number) { async findAll(
const [data, count] = await this.productService.findAll(page); @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 { return {
data, ...data,
count,
statusCode: HttpStatus.OK, statusCode: HttpStatus.OK,
message: 'success', message: 'success',
}; };
@ -98,12 +107,12 @@ export class ProductController {
@Get('by-categories-all') @Get('by-categories-all')
async findByCategoriesAll( async findByCategoriesAll(
@Query('page') page: number, @Query('page') page: number,
@Query('categories') categories: string, @Query('sub-category') subcategory: string,
@Query('supplier') supplier: string, @Query('supplier') supplier: string,
) { ) {
const data = await this.productService.findAllBySubCategories( const data = await this.productService.findAllBySubCategories(
page, page,
categories, subcategory,
supplier, supplier,
); );
@ -148,12 +157,14 @@ export class ProductController {
} }
@Get('sub-categories') @Get('sub-categories')
async findAllSubCategories(@Query('page') page: number) { async findAllSubCategories(
const [data, count] = await this.productSubCategoriesService.findAll(page); @Query('page') page: number,
@Query('category') category: string,
) {
const data = await this.productSubCategoriesService.findAll(page, category);
return { return {
data, ...data,
count,
statusCode: HttpStatus.OK, statusCode: HttpStatus.OK,
message: 'success', message: 'success',
}; };
@ -168,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') @Put(':id')
async update( async update(
@Param('id', ParseUUIDPipe) id: string, @Param('id', ParseUUIDPipe) id: string,

View File

@ -15,6 +15,7 @@ import { productType } from '../helper/enum-list';
import { UpdatePriceProductDto } from './dto/product/update-price-product.dto'; import { UpdatePriceProductDto } from './dto/product/update-price-product.dto';
import { UsersService } from '../users/users.service'; import { UsersService } from '../users/users.service';
import { SupplierService } from '../users/supplier/supplier.service'; import { SupplierService } from '../users/supplier/supplier.service';
import { type } from 'os';
export class ProductService { export class ProductService {
constructor( constructor(
@ -52,17 +53,49 @@ export class ProductService {
return this.productRepository.findOneOrFail(result.identifiers[0].id); return this.productRepository.findOneOrFail(result.identifiers[0].id);
} }
findAll(page) { async findAll(page, supplier, categories, subCategories) {
return this.productRepository.findAndCount({ if (supplier == 'null' || !supplier) {
skip: page * 10, supplier = (await this.supplierService.findByActive()).id;
relations: ['sub_categories'], }
take: 10, const baseQuery = this.productRepository
order: { .createQueryBuilder('product')
version: 'DESC', .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) { async findAllByCategories(page, subCategories, supplier) {
const baseQuery = this.productRepository const baseQuery = this.productRepository
.createQueryBuilder('product') .createQueryBuilder('product')
@ -95,16 +128,15 @@ export class ProductService {
} }
async findAllBySubCategories(page, subCategories, supplier) { async findAllBySubCategories(page, subCategories, supplier) {
if (supplier != 'null' && !supplier) {
supplier = (await this.supplierService.findByActive()).id;
}
const baseQuery = this.productRepository const baseQuery = this.productRepository
.createQueryBuilder('product') .createQueryBuilder('product')
.leftJoin('product.sub_categories', 'sub_categories') .leftJoin('product.sub_categories', 'sub_categories')
.where( .where('product.supplier_id = :supplier_id', {
'sub_categories.category_id = :id and product.supplier_id = :supplier_id',
{
id: subCategories,
supplier_id: supplier, supplier_id: supplier,
}, })
)
.leftJoinAndMapOne( .leftJoinAndMapOne(
'product.currentPrice', 'product.currentPrice',
'product.priceHistory', 'product.priceHistory',
@ -112,6 +144,12 @@ export class ProductService {
'current_price.partner_id is null', 'current_price.partner_id is null',
); );
if (subCategories != 'null' && subCategories) {
baseQuery.where('product.sub_categories_id = :id', {
id: subCategories,
});
}
const data = await baseQuery const data = await baseQuery
.skip(page * 10) .skip(page * 10)
.take(10) .take(10)
@ -178,7 +216,7 @@ export class ProductService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Product not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -196,7 +234,7 @@ export class ProductService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Product not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -245,7 +283,7 @@ export class ProductService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Product not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );

View File

@ -66,7 +66,7 @@ export class CoaService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'COA not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );

View File

@ -164,7 +164,7 @@ export class SupplierService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'Supplier not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );

View File

@ -205,7 +205,7 @@ export class UsersService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'User not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -228,7 +228,7 @@ export class UsersService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'User not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -258,7 +258,7 @@ export class UsersService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'User not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -276,7 +276,7 @@ export class UsersService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'User not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -337,7 +337,7 @@ export class UsersService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'User not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );
@ -371,7 +371,7 @@ export class UsersService {
throw new HttpException( throw new HttpException(
{ {
statusCode: HttpStatus.NOT_FOUND, statusCode: HttpStatus.NOT_FOUND,
error: 'Data not found', error: 'User not found',
}, },
HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND,
); );