Merge branch 'development' into 'devops-staging'

Development

See merge request empatnusabangsa/ppob/ppob-backend!26
This commit is contained in:
ilham dwi pratama 2021-12-16 08:06:07 +00:00
commit 0a8c75a768
6 changed files with 63 additions and 14 deletions

View File

@ -101,7 +101,7 @@ export class ProductController {
@Query('categories') categories: string,
@Query('supplier') supplier: string,
) {
const data = await this.productService.findAllByCategories(
const data = await this.productService.findAllBySubCategories(
page,
categories,
supplier,

View File

@ -63,14 +63,45 @@ export class ProductService {
});
}
async findAllByCategories(page, categories, supplier) {
async findAllByCategories(page, subCategories, supplier) {
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: categories,
id: subCategories,
supplier_id: supplier,
},
)
.leftJoinAndMapOne(
'product.currentPrice',
'product.priceHistory',
'current_price',
'current_price.partner_id is null',
);
const data = await baseQuery
.skip(page * 10)
.take(10)
.getMany();
const totalData = await baseQuery.getCount();
return {
data,
count: totalData,
};
}
async findAllBySubCategories(page, subCategories, supplier) {
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,
},
)

View File

@ -27,6 +27,7 @@ export class COA extends BaseModel {
relatedUser: string;
@Column({
type: 'uuid',
nullable: true,
})
supplier: string;

View File

@ -2,6 +2,7 @@ import { Roles } from 'src/configurable/entities/roles.entity';
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
import { BaseModel } from '../../config/basemodel.entity';
import { hashPassword } from '../../helper/hash_password';
import { COA } from '../../transaction/entities/coa.entity';
@Entity()
export class Supplier extends BaseModel {
@ -16,4 +17,6 @@ export class Supplier extends BaseModel {
@Column()
status: boolean;
coa: COA;
}

View File

@ -14,6 +14,7 @@ import { CreateSupplierDto } from '../dto/create-supplier.dto';
import { CoaService } from '../../transaction/coa.service';
import * as uuid from 'uuid';
import { UpdateSupplierDto } from '../dto/update-supplier.dto';
import { COA } from '../../transaction/entities/coa.entity';
@Injectable()
export class SupplierService {
@ -129,14 +130,28 @@ export class SupplierService {
return supplierData;
};
findAllSupplier(page) {
return this.supplierRepository.findAndCount({
skip: page * 10,
take: 10,
order: {
version: 'DESC',
},
});
async findAllSupplier(page) {
const baseQuery = this.supplierRepository
.createQueryBuilder('supplier')
.leftJoinAndMapOne(
'supplier.coa',
COA,
'coa',
`coa.supplier = supplier.id`,
)
.select(['supplier', 'coa.amount']);
const data = await baseQuery
.skip(page * 10)
.take(10)
.getMany();
const totalData = await baseQuery.getCount();
return {
data,
count: totalData,
};
}
async findByCode(code: string) {

View File

@ -130,11 +130,10 @@ export class UsersController {
@Public()
@Get('supplier')
async findAllSupplier(@Query('page') page: number) {
const [data, count] = await this.supplierService.findAllSupplier(page);
const data = await this.supplierService.findAllSupplier(page);
return {
data,
count,
...data,
statusCode: HttpStatus.OK,
message: 'success',
};