Compare commits
No commits in common. "45080ae65a0cdf55ddaf41bf044ee9f19bc0fc1b" and "9ad62d28aacb25fcb8f4495714b636c3292fb24d" have entirely different histories.
45080ae65a
...
9ad62d28aa
|
|
@ -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