Compare commits
	
		
			No commits in common. "0e3dcd712c6f4a9006e0603e05d8399bfad3ad8a" and "e48f4983484df4f45bc74aaa3a5a42d83343ae62" have entirely different histories.
		
	
	
		
			0e3dcd712c
			...
			e48f498348
		
	
		| 
						 | 
					@ -1,10 +1,16 @@
 | 
				
			||||||
import { WebBidsService } from '@/modules/bids/services/web-bids.service';
 | 
					 | 
				
			||||||
import AppResponse from '@/response/app-response';
 | 
					 | 
				
			||||||
import { BadRequestException, Injectable } from '@nestjs/common';
 | 
					import { BadRequestException, Injectable } from '@nestjs/common';
 | 
				
			||||||
import { InjectRepository } from '@nestjs/typeorm';
 | 
					import { InjectRepository } from '@nestjs/typeorm';
 | 
				
			||||||
import { paginate, PaginateQuery } from 'nestjs-paginate';
 | 
					 | 
				
			||||||
import { Repository } from 'typeorm';
 | 
					import { Repository } from 'typeorm';
 | 
				
			||||||
import { ScrapItem } from '../entities/scrap-item.entity';
 | 
					import { ScrapItem } from '../entities/scrap-item.entity';
 | 
				
			||||||
 | 
					import AppResponse from '@/response/app-response';
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
					  FilterOperator,
 | 
				
			||||||
 | 
					  FilterSuffix,
 | 
				
			||||||
 | 
					  paginate,
 | 
				
			||||||
 | 
					  PaginateQuery,
 | 
				
			||||||
 | 
					} from 'nestjs-paginate';
 | 
				
			||||||
 | 
					import { Column } from 'nestjs-paginate/lib/helper';
 | 
				
			||||||
 | 
					import { WebBidsService } from '@/modules/bids/services/web-bids.service';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Injectable()
 | 
					@Injectable()
 | 
				
			||||||
export class ScrapItemsService {
 | 
					export class ScrapItemsService {
 | 
				
			||||||
| 
						 | 
					@ -72,7 +78,7 @@ export class ScrapItemsService {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async index(query: PaginateQuery) {
 | 
					  async index(query: PaginateQuery) {
 | 
				
			||||||
    const { data, meta } = await paginate(query, this.scrapItemRepo, {
 | 
					    const data = await paginate(query, this.scrapItemRepo, {
 | 
				
			||||||
      sortableColumns: ['id'],
 | 
					      sortableColumns: ['id'],
 | 
				
			||||||
      searchableColumns: ['id'],
 | 
					      searchableColumns: ['id'],
 | 
				
			||||||
      defaultLimit: 15,
 | 
					      defaultLimit: 15,
 | 
				
			||||||
| 
						 | 
					@ -81,26 +87,16 @@ export class ScrapItemsService {
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      defaultSortBy: [['updated_at', 'DESC']],
 | 
					      defaultSortBy: [['updated_at', 'DESC']],
 | 
				
			||||||
      maxLimit: 100,
 | 
					      maxLimit: 100,
 | 
				
			||||||
      relations: { scrap_config: { web_bid: true } },
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const sources = await this.webService.webBidRepo.find({
 | 
					    const sources = await this.webService.webBidRepo.find({
 | 
				
			||||||
      select: { origin_url: true },
 | 
					      select: { origin_url: true },
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const newData = data.map(({ scrap_config, ...item }) => {
 | 
					    return AppResponse.toPagination<ScrapItem>(
 | 
				
			||||||
      return {
 | 
					      { ...data, bonus: { sources } },
 | 
				
			||||||
        ...item,
 | 
					      true,
 | 
				
			||||||
        source: scrap_config.web_bid.origin_url,
 | 
					      ScrapItem,
 | 
				
			||||||
      };
 | 
					    );
 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return AppResponse.toPaginationAny({
 | 
					 | 
				
			||||||
      data: newData,
 | 
					 | 
				
			||||||
      meta,
 | 
					 | 
				
			||||||
      bonus: {
 | 
					 | 
				
			||||||
        sources: sources.map((item) => item.origin_url),
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,32 +50,6 @@ export default class AppResponse {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public static toPaginationAny(
 | 
					 | 
				
			||||||
    { data, meta, bonus }: any,
 | 
					 | 
				
			||||||
    transform = true,
 | 
					 | 
				
			||||||
    dtoClass?: new () => any,
 | 
					 | 
				
			||||||
  ) {
 | 
					 | 
				
			||||||
    const transformedData =
 | 
					 | 
				
			||||||
      transform && dtoClass
 | 
					 | 
				
			||||||
        ? data.map((item) => plainToClass(dtoClass, item))
 | 
					 | 
				
			||||||
        : data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return this.toResponse(transformedData, {
 | 
					 | 
				
			||||||
      bonus: {
 | 
					 | 
				
			||||||
        current_page: meta.currentPage,
 | 
					 | 
				
			||||||
        from: meta.currentPage * meta.itemsPerPage - (meta.itemsPerPage - 1),
 | 
					 | 
				
			||||||
        to:
 | 
					 | 
				
			||||||
          meta.currentPage * meta.itemsPerPage > meta.totalItems
 | 
					 | 
				
			||||||
            ? meta.totalItems
 | 
					 | 
				
			||||||
            : meta.currentPage * meta.itemsPerPage,
 | 
					 | 
				
			||||||
        last_page: meta.totalPages,
 | 
					 | 
				
			||||||
        per_page: meta.itemsPerPage,
 | 
					 | 
				
			||||||
        total: meta.totalItems,
 | 
					 | 
				
			||||||
        ...bonus,
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  public static processFilters<T>(
 | 
					  public static processFilters<T>(
 | 
				
			||||||
    queryFilters: any,
 | 
					    queryFilters: any,
 | 
				
			||||||
    filterableColumns: {
 | 
					    filterableColumns: {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue