Merge branch 'development' into 'devops-staging'
fix: order history and add filter See merge request empatnusabangsa/ppob/ppob-backend!74
This commit is contained in:
		@@ -117,11 +117,13 @@ export class TransactionController {
 | 
			
		||||
  async getHistoryTransactionUser(
 | 
			
		||||
    @Query('page') page: number,
 | 
			
		||||
    @Query('pageSize') pageSize: number,
 | 
			
		||||
    @Query('transactionDate') transactionDate: string,
 | 
			
		||||
    @Request() req,
 | 
			
		||||
  ) {
 | 
			
		||||
    const data = await this.transactionService.transactionHistoryByUser(
 | 
			
		||||
      page,
 | 
			
		||||
      req.user.userId,
 | 
			
		||||
      transactionDate,
 | 
			
		||||
      pageSize,
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -765,14 +765,32 @@ export class TransactionService {
 | 
			
		||||
  async transactionHistoryByUser(
 | 
			
		||||
    page: number,
 | 
			
		||||
    user: string,
 | 
			
		||||
    transactionDate: string,
 | 
			
		||||
    pageSize?: number,
 | 
			
		||||
  ) {
 | 
			
		||||
    const userData = await this.userService.findExist(user);
 | 
			
		||||
    let filterTransactionDate;
 | 
			
		||||
 | 
			
		||||
    let userBySupperior = [];
 | 
			
		||||
    if(userData.roles.id != 'e4dfb6a3-2338-464a-8fb8-5cbc089d4209' && userData.roles.id != '21dceea2-416e-4b55-b74c-12605e1f8d1b'){
 | 
			
		||||
      const getListUser = await this.userService.findBySuperrior(userData.id,100)
 | 
			
		||||
      userBySupperior = getListUser.data.map(x => x.id)
 | 
			
		||||
    } else {
 | 
			
		||||
      userBySupperior.push(user)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (transactionDate) {
 | 
			
		||||
      filterTransactionDate = transactionDate.split(',').map((data) => {
 | 
			
		||||
        return data.trim();
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const baseQuery = this.transactionRepository
 | 
			
		||||
      .createQueryBuilder('transaction')
 | 
			
		||||
      .select('transaction.id', 'id')
 | 
			
		||||
      .addSelect('transaction.created_at', 'created_at')
 | 
			
		||||
      .where('transaction.user = :id and transaction.type = 1', {
 | 
			
		||||
        id: user,
 | 
			
		||||
      .where('transaction.user = IN (:...id) and transaction.type = 1', {
 | 
			
		||||
        id: userBySupperior,
 | 
			
		||||
      })
 | 
			
		||||
      .leftJoin('transaction.product_price', 'product_price')
 | 
			
		||||
      .leftJoin('product_price.product', 'product')
 | 
			
		||||
@@ -780,8 +798,12 @@ export class TransactionService {
 | 
			
		||||
      .addSelect('product.name', 'name')
 | 
			
		||||
      .addSelect('product.id', 'product_id');
 | 
			
		||||
 | 
			
		||||
    // .leftJoinAndSelect('transaction.product_price', 'product_price')
 | 
			
		||||
    // .leftJoinAndSelect('product_price.product', 'product');
 | 
			
		||||
    if (transactionDate && filterTransactionDate.length > 0) {
 | 
			
		||||
      baseQuery.where('transaction.created_at between :startDate and :enDate', {
 | 
			
		||||
        startDate: filterTransactionDate[0],
 | 
			
		||||
        enDate: filterTransactionDate[0],
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const data = await baseQuery
 | 
			
		||||
      .offset(page * (pageSize || 10))
 | 
			
		||||
 
 | 
			
		||||
@@ -238,7 +238,7 @@ export class UsersService {
 | 
			
		||||
        where: {
 | 
			
		||||
          id: id,
 | 
			
		||||
        },
 | 
			
		||||
        relations: ['superior'],
 | 
			
		||||
        relations: ['superior','roles'],
 | 
			
		||||
      });
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      if (e instanceof EntityNotFoundError) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user