Merge branch 'development' into 'devops-staging'
Development See merge request empatnusabangsa/ppob/ppob-backend!33
This commit is contained in:
commit
051ae989e4
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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({
|
||||
skip: page * 10,
|
||||
take: 10,
|
||||
where: {
|
||||
category: category,
|
||||
},
|
||||
relations: ['category'],
|
||||
order: {
|
||||
version: 'DESC',
|
||||
|
@ -63,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,
|
||||
);
|
||||
|
@ -84,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,
|
||||
);
|
||||
|
@ -113,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,
|
||||
);
|
||||
|
|
|
@ -69,13 +69,22 @@ export class ProductController {
|
|||
};
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll(@Query('page') page: number) {
|
||||
const [data, count] = await this.productService.findAll(page);
|
||||
@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',
|
||||
};
|
||||
|
@ -98,12 +107,12 @@ export class ProductController {
|
|||
@Get('by-categories-all')
|
||||
async findByCategoriesAll(
|
||||
@Query('page') page: number,
|
||||
@Query('categories') categories: string,
|
||||
@Query('sub-category') subcategory: string,
|
||||
@Query('supplier') supplier: string,
|
||||
) {
|
||||
const data = await this.productService.findAllBySubCategories(
|
||||
page,
|
||||
categories,
|
||||
subcategory,
|
||||
supplier,
|
||||
);
|
||||
|
||||
|
@ -148,12 +157,14 @@ 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',
|
||||
};
|
||||
|
@ -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')
|
||||
async update(
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
|
|
|
@ -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(
|
||||
|
@ -52,17 +53,49 @@ 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) {
|
||||
const baseQuery = this.productRepository
|
||||
.createQueryBuilder('product')
|
||||
|
@ -95,16 +128,15 @@ export class ProductService {
|
|||
}
|
||||
|
||||
async findAllBySubCategories(page, subCategories, supplier) {
|
||||
if (supplier != 'null' && !supplier) {
|
||||
supplier = (await this.supplierService.findByActive()).id;
|
||||
}
|
||||
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,
|
||||
.where('product.supplier_id = :supplier_id', {
|
||||
supplier_id: supplier,
|
||||
},
|
||||
)
|
||||
})
|
||||
.leftJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
|
@ -112,6 +144,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)
|
||||
|
@ -178,7 +216,7 @@ export class ProductService {
|
|||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Data not found',
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
|
@ -196,7 +234,7 @@ export class ProductService {
|
|||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Data not found',
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
|
@ -245,7 +283,7 @@ export class ProductService {
|
|||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Data not found',
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user