添加最新热搜查询
This commit is contained in:
parent
1c4c07c82e
commit
5c2018b407
@ -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()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user