修复判断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 { NextFunction, Request, Response } from "express"
 | 
			
		||||
 | 
			
		||||
export class HotTopController{
 | 
			
		||||
export class HotTopController {
 | 
			
		||||
    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 yestDay = new Date()
 | 
			
		||||
 | 
			
		||||
        let hours = 1
 | 
			
		||||
        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)
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            response.status(404)
 | 
			
		||||
            return "error"
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        yestDay.setHours(nowDate.getHours() - hours)
 | 
			
		||||
        // console.log(yestDay.toLocaleString())
 | 
			
		||||
        let limit:number
 | 
			
		||||
        if(request.query.limit) limit = parseInt(request.query.limit as unknown as string)
 | 
			
		||||
        if(isNaN(limit) || limit>50 || limit<1) limit = 10
 | 
			
		||||
        let limit: number
 | 
			
		||||
        if (request.query.limit == undefined) {
 | 
			
		||||
            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)
 | 
			
		||||
        // return "OK"
 | 
			
		||||
@ -25,12 +37,12 @@ export class HotTopController{
 | 
			
		||||
            .createQueryBuilder("time")
 | 
			
		||||
            .leftJoinAndSelect("time.fromWeb", "fromWeb")
 | 
			
		||||
            .where("time.lastTime BETWEEN :beginTime AND :endTime",
 | 
			
		||||
                    {
 | 
			
		||||
                        beginTime:yestDay,
 | 
			
		||||
                        endTime:nowDate
 | 
			
		||||
                    }
 | 
			
		||||
                )
 | 
			
		||||
            .addOrderBy('time.times',"DESC")
 | 
			
		||||
                {
 | 
			
		||||
                    beginTime: yestDay,
 | 
			
		||||
                    endTime: nowDate
 | 
			
		||||
                }
 | 
			
		||||
            )
 | 
			
		||||
            .addOrderBy('time.times', "DESC")
 | 
			
		||||
            .limit(limit)
 | 
			
		||||
            .getMany()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user