diff --git a/src/controller/GetNewWebsController.ts b/src/controller/GetNewWebsController.ts index 1cbd769..ac8b711 100644 --- a/src/controller/GetNewWebsController.ts +++ b/src/controller/GetNewWebsController.ts @@ -1,7 +1,45 @@ import { Request, Response, NextFunction } from "express"; +import { AppDataSource } from "../data-source"; +import { Web } from "../entity/Web"; +import { Search } from "../entity/Search"; +import { Hot } from "../entity/Hot"; export class GetNewWebsController{ async all(request: Request, response: Response, next: NextFunction){ - + const name = request.params.name + const searchWeb = await AppDataSource.getRepository(Web).findOne({ + where:{ + name:name + } + }) + if(searchWeb == null){ + response.status(404) + return "error" + } + const limit = Number.parseInt(request.query.limit as string) + if(isNaN(limit)||limit<1||limit>25){ + response.status(404) + return "error" + } + const lastSearch = await AppDataSource + .getRepository(Search) + .createQueryBuilder("search") + .where("search.fromWeb = :fromWeb", + { + fromWeb:searchWeb.id + } + ) + .orderBy("search.id","DESC") + .getOne() + return AppDataSource + .getRepository(Hot) + .createQueryBuilder("hot") + .where("hot.fromSearch = :fromSearch", + { + fromSearch:lastSearch.id + } + ) + .limit(limit) + .getMany() } } \ No newline at end of file