Merge branch 'development' into 'devops-staging'
Development See merge request empatnusabangsa/ppob/ppob-backend!26
This commit is contained in:
commit
0a8c75a768
|
@ -101,7 +101,7 @@ export class ProductController {
|
||||||
@Query('categories') categories: string,
|
@Query('categories') categories: string,
|
||||||
@Query('supplier') supplier: string,
|
@Query('supplier') supplier: string,
|
||||||
) {
|
) {
|
||||||
const data = await this.productService.findAllByCategories(
|
const data = await this.productService.findAllBySubCategories(
|
||||||
page,
|
page,
|
||||||
categories,
|
categories,
|
||||||
supplier,
|
supplier,
|
||||||
|
|
|
@ -63,14 +63,45 @@ export class ProductService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllByCategories(page, categories, supplier) {
|
async findAllByCategories(page, subCategories, supplier) {
|
||||||
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(
|
||||||
'sub_categories.category_id = :id and product.supplier_id = :supplier_id',
|
'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,
|
supplier_id: supplier,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ export class COA extends BaseModel {
|
||||||
relatedUser: string;
|
relatedUser: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
|
type: 'uuid',
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
supplier: string;
|
supplier: string;
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { Roles } from 'src/configurable/entities/roles.entity';
|
||||||
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
|
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
|
||||||
import { BaseModel } from '../../config/basemodel.entity';
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { hashPassword } from '../../helper/hash_password';
|
import { hashPassword } from '../../helper/hash_password';
|
||||||
|
import { COA } from '../../transaction/entities/coa.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Supplier extends BaseModel {
|
export class Supplier extends BaseModel {
|
||||||
|
@ -16,4 +17,6 @@ export class Supplier extends BaseModel {
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
status: boolean;
|
status: boolean;
|
||||||
|
|
||||||
|
coa: COA;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { CreateSupplierDto } from '../dto/create-supplier.dto';
|
||||||
import { CoaService } from '../../transaction/coa.service';
|
import { CoaService } from '../../transaction/coa.service';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import { UpdateSupplierDto } from '../dto/update-supplier.dto';
|
import { UpdateSupplierDto } from '../dto/update-supplier.dto';
|
||||||
|
import { COA } from '../../transaction/entities/coa.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SupplierService {
|
export class SupplierService {
|
||||||
|
@ -129,14 +130,28 @@ export class SupplierService {
|
||||||
return supplierData;
|
return supplierData;
|
||||||
};
|
};
|
||||||
|
|
||||||
findAllSupplier(page) {
|
async findAllSupplier(page) {
|
||||||
return this.supplierRepository.findAndCount({
|
const baseQuery = this.supplierRepository
|
||||||
skip: page * 10,
|
.createQueryBuilder('supplier')
|
||||||
take: 10,
|
.leftJoinAndMapOne(
|
||||||
order: {
|
'supplier.coa',
|
||||||
version: 'DESC',
|
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) {
|
async findByCode(code: string) {
|
||||||
|
|
|
@ -130,11 +130,10 @@ export class UsersController {
|
||||||
@Public()
|
@Public()
|
||||||
@Get('supplier')
|
@Get('supplier')
|
||||||
async findAllSupplier(@Query('page') page: number) {
|
async findAllSupplier(@Query('page') page: number) {
|
||||||
const [data, count] = await this.supplierService.findAllSupplier(page);
|
const data = await this.supplierService.findAllSupplier(page);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
...data,
|
||||||
count,
|
|
||||||
statusCode: HttpStatus.OK,
|
statusCode: HttpStatus.OK,
|
||||||
message: 'success',
|
message: 'success',
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user