Skip to content

Commit

Permalink
Statistics count (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 authored Aug 20, 2023
1 parent f0f4c09 commit 85e75d1
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 10 deletions.
21 changes: 16 additions & 5 deletions src/popo/introduce/association/intro.association.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
UseGuards,
} from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Between } from 'typeorm';
import * as moment from 'moment';

import { IntroAssociationService } from './intro.association.service';
import { CreateIntroAssociationDto } from './intro.association.dto';
Expand Down Expand Up @@ -53,12 +55,16 @@ export class IntroAssociationController {
get() {
return this.introAssociationService.find({ order: { name: 'ASC' } });
}

@Get(':uuid')
getOneByUuid(@Param('uuid') uuid: string) {
return this.introAssociationService.findOneByUuid(uuid);

@Get('today')
getTodayVisited() {
return this.introAssociationService.find({
where: {
updateAt: Between(moment().startOf('day').toDate(), moment().endOf('day').toDate()),
}
});
}

@Get('name/:name')
async getOneByName(@Param('name') name: string) {
const introAssociation = await this.introAssociationService.findOneByName(name);
Expand All @@ -74,6 +80,11 @@ export class IntroAssociationController {
}
}

@Get(':uuid')
getOneByUuid(@Param('uuid') uuid: string) {
return this.introAssociationService.findOneByUuid(uuid);
}

@Put(':uuid')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserType.admin, UserType.association)
Expand Down
21 changes: 16 additions & 5 deletions src/popo/introduce/club/intro.club.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
UseGuards,
} from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Between } from 'typeorm';
import * as moment from 'moment';

import { IntroClubService } from './intro.club.service';
import { JwtAuthGuard } from '../../../auth/guards/jwt-auth.guard';
Expand Down Expand Up @@ -53,6 +55,15 @@ export class IntroClubController {
get() {
return this.introClubService.find({ order: { name: 'ASC' } });
}

@Get('today')
getTodayVisited() {
return this.introClubService.find({
where: {
updateAt: Between(moment().startOf('day').toDate(), moment().endOf('day').toDate()),
}
})
}

@Get('clubType/:clubType')
getByClubType(@Param('clubType') clubType: ClubType) {
Expand All @@ -62,11 +73,6 @@ export class IntroClubController {
});
}

@Get(':uuid')
getOneByUuid(@Param('uuid') uuid: string) {
return this.introClubService.findOneByUuid(uuid);
}

@Get('name/:name')
async getOneByName(@Param('name') name: string) {
const introClub = await this.introClubService.findOneByName(name);
Expand All @@ -81,6 +87,11 @@ export class IntroClubController {
throw new BadRequestException('Not Exist');
}
}

@Get(':uuid')
getOneByUuid(@Param('uuid') uuid: string) {
return this.introClubService.findOneByUuid(uuid);
}

@Put(':uuid')
@UseGuards(JwtAuthGuard, RolesGuard)
Expand Down
26 changes: 26 additions & 0 deletions src/statistics/reservation.statistics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,30 @@ export class ReservationStatisticsController {
data: data,
};
}

@Get('count')
async countInfo() {
moment.updateLocale('en', {
week: {
dow : 1, // Monday is the first day of the week.
}
});


const totalReservationCnt = await this.reservePlaceService.count();

const todayReservationCnt = await this.reservePlaceService.count({
created_at: Between(moment().startOf('day').toDate(), moment().endOf('day').toDate())
});

const thisWeekReservationCnt = await this.reservePlaceService.count({
created_at: Between(moment().startOf('week').toDate(), moment().endOf('week').toDate())
});

return {
totalReservationCnt,
todayReservationCnt,
thisWeekReservationCnt,
}
}
}
33 changes: 33 additions & 0 deletions src/statistics/user.statistics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,37 @@ export class UserStatisticsController {
data: data,
};
}

@Get('count')
async countInfo() {
moment.updateLocale('en', {
week: {
dow : 1, // Monday is the first day of the week.
}
});

const totalUserCnt = await this.userService.count();

const todayRegisterUserCnt = await this.userService.count({
createdAt: Between(moment().startOf('day').toDate(), moment().endOf('day').toDate())
});
const todayLoginUserCnt = await this.userService.count({
lastLoginAt: Between(moment().startOf('day').toDate(), moment().endOf('day').toDate())
});

const thisWeekRegisterUserCnt = await this.userService.count({
createdAt: Between(moment().startOf('week').toDate(), moment().endOf('week').toDate())
});
const thisWeekLoginUserCnt = await this.userService.count({
lastLoginAt: Between(moment().startOf('week').toDate(), moment().endOf('week').toDate())
});

return {
totalUserCnt,
todayRegisterUserCnt,
todayLoginUserCnt,
thisWeekRegisterUserCnt,
thisWeekLoginUserCnt,
}
}
}

0 comments on commit 85e75d1

Please sign in to comment.