修复判断bug
This commit is contained in:
parent
56b1a8617f
commit
ff40cc6a27
@ -2,22 +2,34 @@ import { AppDataSource } from "../data-source";
|
|||||||
import { Times } from "../entity/Times";
|
import { Times } from "../entity/Times";
|
||||||
import { NextFunction, Request, Response } from "express"
|
import { NextFunction, Request, Response } from "express"
|
||||||
|
|
||||||
export class HotTopController{
|
export class HotTopController {
|
||||||
private TimesRepository = AppDataSource.getRepository(Times)
|
private TimesRepository = AppDataSource.getRepository(Times)
|
||||||
async all(request: Request, response: Response, next: NextFunction){
|
async all(request: Request, response: Response, next: NextFunction) {
|
||||||
const nowDate = new Date()
|
const nowDate = new Date()
|
||||||
const yestDay = new Date()
|
const yestDay = new Date()
|
||||||
|
|
||||||
let hours = 1
|
let hours = 1
|
||||||
let rawHours = parseInt(request.query.hours as unknown as string)
|
let rawHours = parseInt(request.query.hours as unknown as string)
|
||||||
if(request.query.hours && !isNaN(rawHours) && rawHours <=24 && rawHours > 0)
|
if (request.query.hours !=undefined && !isNaN(rawHours) && rawHours <= 24 && rawHours > 0) {
|
||||||
hours = parseInt(request.query.hours as unknown as string)
|
hours = parseInt(request.query.hours as unknown as string)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
response.status(404)
|
||||||
|
return "error"
|
||||||
|
}
|
||||||
|
|
||||||
yestDay.setHours(nowDate.getHours() - hours)
|
yestDay.setHours(nowDate.getHours() - hours)
|
||||||
// console.log(yestDay.toLocaleString())
|
// console.log(yestDay.toLocaleString())
|
||||||
let limit:number
|
let limit: number
|
||||||
if(request.query.limit) limit = parseInt(request.query.limit as unknown as string)
|
if (request.query.limit == undefined) {
|
||||||
if(isNaN(limit) || limit>50 || limit<1) limit = 10
|
response.status(404)
|
||||||
|
return "error"
|
||||||
|
}
|
||||||
|
limit = Number.parseInt(request.query.limit as string)
|
||||||
|
if (isNaN(limit) || limit > 50 || limit < 1) {
|
||||||
|
response.status(404)
|
||||||
|
return "error"
|
||||||
|
}
|
||||||
|
|
||||||
// console.log(limit,hours)
|
// console.log(limit,hours)
|
||||||
// return "OK"
|
// return "OK"
|
||||||
@ -25,12 +37,12 @@ export class HotTopController{
|
|||||||
.createQueryBuilder("time")
|
.createQueryBuilder("time")
|
||||||
.leftJoinAndSelect("time.fromWeb", "fromWeb")
|
.leftJoinAndSelect("time.fromWeb", "fromWeb")
|
||||||
.where("time.lastTime BETWEEN :beginTime AND :endTime",
|
.where("time.lastTime BETWEEN :beginTime AND :endTime",
|
||||||
{
|
{
|
||||||
beginTime:yestDay,
|
beginTime: yestDay,
|
||||||
endTime:nowDate
|
endTime: nowDate
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.addOrderBy('time.times',"DESC")
|
.addOrderBy('time.times', "DESC")
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.getMany()
|
.getMany()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user