Commit cc784dd1 authored by nanahira's avatar nanahira

add /api/homepageCount

parent 72963a50
Pipeline #4033 passed with stages
in 5 minutes and 23 seconds
...@@ -30,6 +30,7 @@ import cryptoRandomString from 'crypto-random-string'; ...@@ -30,6 +30,7 @@ import cryptoRandomString from 'crypto-random-string';
import { join } from 'path'; import { join } from 'path';
import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger'; import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
import { FileUploadDto } from './dto/FileUploadDto'; import { FileUploadDto } from './dto/FileUploadDto';
import { HomePageMatchCountDto } from './dto/HomePageMatchCount.dto';
@Controller('api') @Controller('api')
@ApiTags('arena') @ApiTags('arena')
...@@ -265,4 +266,9 @@ export class AppController { ...@@ -265,4 +266,9 @@ export class AppController {
async getFirstWinActivity(@Query('username') username: string) { async getFirstWinActivity(@Query('username') username: string) {
return await this.appService.getFirstWinActivity(username); return await this.appService.getFirstWinActivity(username);
} }
@Get('homepageCount')
async getLastMonthBattleCount(): Promise<HomePageMatchCountDto> {
return this.appService.getLastMonthBattleCount();
}
} }
...@@ -37,6 +37,7 @@ import { DeckInfoOrHistory } from './entities/mycard/DeckInfoOrHistory'; ...@@ -37,6 +37,7 @@ import { DeckInfoOrHistory } from './entities/mycard/DeckInfoOrHistory';
import { EloService } from './elo/elo.service'; import { EloService } from './elo/elo.service';
import { CardInfoService } from './card-info/card-info.service'; import { CardInfoService } from './card-info/card-info.service';
import { AthleticCheckerService } from './athletic-checker/athletic-checker.service'; import { AthleticCheckerService } from './athletic-checker/athletic-checker.service';
import { HomePageMatchCountDto } from './dto/HomePageMatchCount.dto';
const attrOffset = 1010; const attrOffset = 1010;
const raceOffset = 1020; const raceOffset = 1020;
...@@ -1761,4 +1762,19 @@ export class AppService { ...@@ -1761,4 +1762,19 @@ export class AppService {
).toString(); ).toString();
return activity; return activity;
} }
async getLastMonthBattleCount() {
const lastMonth = moment().subtract(1, 'month');
const fromTime = moment(lastMonth);
fromTime.set({ day: 1, hour: 0, minute: 0, second: 0 });
const toTime = moment(fromTime).add(1, 'month');
//this.log.log(`${fromTime} - ${toTime}`);
const count = await this.mcdb.getRepository(BattleHistory).count({
where: {
end_time: MoreThanOrEqual(fromTime.toDate()),
start_time: LessThanOrEqual(toTime.toDate()),
},
});
return new HomePageMatchCountDto(count);
}
} }
import moment from 'moment';
export class HomePageMatchCountDto {
count: number;
year: number;
month: number;
//date: Date;
constructor(count: number) {
this.count = count;
const now = moment();
const lastMonth = now.subtract(1, 'month');
//this.date = lastMonth.toDate();
this.year = lastMonth.year();
this.month = lastMonth.month() + 1;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment