add api get scrape items
This commit is contained in:
parent
1ac558fe75
commit
69610cbbb5
|
|
@ -90,6 +90,7 @@ import { AdminBidMetadataController } from './controllers/admin/admin-bid-metada
|
||||||
ConfigsService,
|
ConfigsService,
|
||||||
DashboardService,
|
DashboardService,
|
||||||
HotItemApi,
|
HotItemApi,
|
||||||
|
WebBidsService,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class BidsModule {}
|
export class BidsModule {}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { ScrapConfigsService } from '../../services/scrap-config.service';
|
||||||
import { ScrapItemsService } from '../../services/scrap-item-config.service';
|
import { ScrapItemsService } from '../../services/scrap-item-config.service';
|
||||||
import { UpsertScrapItemDto } from '../../dto/scrap-items/upsert-scrap-item.dto';
|
import { UpsertScrapItemDto } from '../../dto/scrap-items/upsert-scrap-item.dto';
|
||||||
import { ScrapItem } from '../../entities/scrap-item.entity';
|
import { ScrapItem } from '../../entities/scrap-item.entity';
|
||||||
|
import { Paginate, PaginateQuery } from 'nestjs-paginate';
|
||||||
|
|
||||||
@Controller('scrap-items')
|
@Controller('scrap-items')
|
||||||
export class ClientScrapItemsController {
|
export class ClientScrapItemsController {
|
||||||
|
|
@ -14,4 +15,9 @@ export class ClientScrapItemsController {
|
||||||
data as ScrapItem[],
|
data as ScrapItem[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async index(@Paginate() query: PaginateQuery) {
|
||||||
|
return await this.scrapItemsService.index(query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,21 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||||
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 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 {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(ScrapItem)
|
@InjectRepository(ScrapItem)
|
||||||
readonly scrapItemRepo: Repository<ScrapItem>,
|
readonly scrapItemRepo: Repository<ScrapItem>,
|
||||||
|
private readonly webService: WebBidsService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async upsertScrapItems(items: ScrapItem[]) {
|
async upsertScrapItems(items: ScrapItem[]) {
|
||||||
|
|
@ -67,4 +76,27 @@ export class ScrapItemsService {
|
||||||
|
|
||||||
return AppResponse.toResponse(rs);
|
return AppResponse.toResponse(rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async index(query: PaginateQuery) {
|
||||||
|
const data = await paginate(query, this.scrapItemRepo, {
|
||||||
|
sortableColumns: ['id'],
|
||||||
|
searchableColumns: ['id'],
|
||||||
|
defaultLimit: 15,
|
||||||
|
filterableColumns: {
|
||||||
|
'scrap_config.web_bid.origin_url': true,
|
||||||
|
},
|
||||||
|
defaultSortBy: [['updated_at', 'DESC']],
|
||||||
|
maxLimit: 100,
|
||||||
|
});
|
||||||
|
|
||||||
|
const sources = await this.webService.webBidRepo.find({
|
||||||
|
select: { origin_url: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
return AppResponse.toPagination<ScrapItem>(
|
||||||
|
{ ...data, bonus: { sources } },
|
||||||
|
true,
|
||||||
|
ScrapItem,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ export default class AppResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static toPagination<M>(
|
public static toPagination<M>(
|
||||||
{ data, meta }: Paginated<M>,
|
{ data, meta, bonus }: Paginated<M> & { bonus?: Record<string, any> },
|
||||||
transform = true,
|
transform = true,
|
||||||
dtoClass?: new () => M,
|
dtoClass?: new () => M,
|
||||||
) {
|
) {
|
||||||
|
|
@ -45,6 +45,7 @@ export default class AppResponse {
|
||||||
last_page: meta.totalPages,
|
last_page: meta.totalPages,
|
||||||
per_page: meta.itemsPerPage,
|
per_page: meta.itemsPerPage,
|
||||||
total: meta.totalItems,
|
total: meta.totalItems,
|
||||||
|
...bonus,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue