Merge branch 'development' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend into development
This commit is contained in:
commit
a17d6922ce
|
@ -1,5 +1,5 @@
|
||||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||||
import { EntityNotFoundError, Repository } from 'typeorm';
|
import { EntityNotFoundError, In, Repository } from 'typeorm';
|
||||||
import { ProductSubCategories } from './entities/product-sub-category.entity';
|
import { ProductSubCategories } from './entities/product-sub-category.entity';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { CreateSubCategoriesProductDto } from './dto/sub-categories/create-sub-categories-product.dto';
|
import { CreateSubCategoriesProductDto } from './dto/sub-categories/create-sub-categories-product.dto';
|
||||||
|
@ -44,14 +44,19 @@ export class ProductSubCategoriesService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(page, category) {
|
async findAll(page, category: string) {
|
||||||
|
let filterCategories;
|
||||||
|
if (category) {
|
||||||
|
filterCategories = category.split(',').map((data) => data.trim());
|
||||||
|
}
|
||||||
|
|
||||||
const baseQuery = this.productSubCategoriesRepository
|
const baseQuery = this.productSubCategoriesRepository
|
||||||
.createQueryBuilder('product_sub_categories')
|
.createQueryBuilder('product_sub_categories')
|
||||||
.leftJoinAndSelect('product_sub_categories.category', 'category');
|
.leftJoinAndSelect('product_sub_categories.category', 'category');
|
||||||
|
|
||||||
if (category != 'null' && category) {
|
if (category && filterCategories.length > 0) {
|
||||||
baseQuery.where({
|
baseQuery.where({
|
||||||
category: category,
|
category: In(filterCategories),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,14 +73,12 @@ export class ProductController {
|
||||||
async findAll(
|
async findAll(
|
||||||
@Query('page') page: number,
|
@Query('page') page: number,
|
||||||
@Query('sub-category') subcategory: string,
|
@Query('sub-category') subcategory: string,
|
||||||
@Query('category') category: string,
|
|
||||||
@Query('supplier') supplier: string,
|
@Query('supplier') supplier: string,
|
||||||
) {
|
) {
|
||||||
const data = await this.productService.findAll(
|
const data = await this.productService.findAll(
|
||||||
page,
|
page,
|
||||||
supplier,
|
JSON.parse(supplier),
|
||||||
category,
|
JSON.parse(subcategory),
|
||||||
subcategory,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -161,7 +159,10 @@ export class ProductController {
|
||||||
@Query('page') page: number,
|
@Query('page') page: number,
|
||||||
@Query('category') category: string,
|
@Query('category') category: string,
|
||||||
) {
|
) {
|
||||||
const data = await this.productSubCategoriesService.findAll(page, category);
|
const data = await this.productSubCategoriesService.findAll(
|
||||||
|
page,
|
||||||
|
JSON.parse(category),
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...data,
|
...data,
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
import {
|
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||||
HttpException,
|
|
||||||
HttpStatus,
|
|
||||||
Injectable,
|
|
||||||
UnauthorizedException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { EntityNotFoundError, Repository } from 'typeorm';
|
import { EntityNotFoundError, Repository } from 'typeorm';
|
||||||
import { Product } from './entities/product.entity';
|
import { Product } from './entities/product.entity';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
@ -15,7 +10,6 @@ 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(
|
||||||
|
@ -53,18 +47,28 @@ export class ProductService {
|
||||||
return this.productRepository.findOneOrFail(result.identifiers[0].id);
|
return this.productRepository.findOneOrFail(result.identifiers[0].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(page, supplier, categories, subCategories) {
|
async findAll(page: number, supplier: string, subCategories: string) {
|
||||||
if (supplier == 'null' || !supplier) {
|
let filterSupplier, filterSubCategories;
|
||||||
supplier = (await this.supplierService.findByActive()).id;
|
if (supplier) {
|
||||||
|
filterSupplier = supplier.split(',').map((data) => data.trim());
|
||||||
}
|
}
|
||||||
|
if (subCategories) {
|
||||||
|
filterSubCategories = subCategories.split(',').map((data) => data.trim());
|
||||||
|
}
|
||||||
|
// if (supplier.length > 0) {
|
||||||
|
// const dataSupplier = await this.supplierService.findByActiveAll();
|
||||||
|
// supplier = dataSupplier.map((item) => item.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')
|
||||||
.leftJoin('sub_categories.category', 'category')
|
.leftJoin('sub_categories.category', 'category')
|
||||||
.where(`product.supplier_id = :supplier_id`, {
|
.leftJoin('product.supplier', 'supplier')
|
||||||
supplier_id: supplier,
|
.where('supplier.status = :status', { status: true })
|
||||||
})
|
// .where(`product.supplier_id = :supplier_id`, {
|
||||||
|
// supplier_id: In(supplier),
|
||||||
|
// })
|
||||||
.leftJoinAndMapOne(
|
.leftJoinAndMapOne(
|
||||||
'product.currentPrice',
|
'product.currentPrice',
|
||||||
'product.priceHistory',
|
'product.priceHistory',
|
||||||
|
@ -81,9 +85,15 @@ export class ProductService {
|
||||||
.addSelect('current_price.price')
|
.addSelect('current_price.price')
|
||||||
.addSelect('(current_price.price + current_price.mark_up_price) as mark_up_price');
|
.addSelect('(current_price.price + current_price.mark_up_price) as mark_up_price');
|
||||||
|
|
||||||
if (subCategories != 'null' && subCategories) {
|
if (subCategories && filterSubCategories.length > 0) {
|
||||||
baseQuery.andWhere('product.sub_categories_id = :id', {
|
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
|
||||||
id: subCategories,
|
subCategoryId: filterSubCategories,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (supplier && filterSupplier.length > 0) {
|
||||||
|
baseQuery.where('supplier.id IN (:...supplierId)', {
|
||||||
|
supplierId: filterSupplier,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,4 +199,24 @@ export class SupplierService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findByActiveAll() {
|
||||||
|
try {
|
||||||
|
return await this.supplierRepository.find({
|
||||||
|
status: true,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
|
error: 'Supplier Data not found',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user