From 85e75d11a6a2f70445228cd510ee2645ce148315 Mon Sep 17 00:00:00 2001 From: Seokyun Ha Date: Sun, 20 Aug 2023 15:37:39 +0900 Subject: [PATCH] Statistics count (#71) --- .../intro.association.controller.ts | 21 +++++++++--- .../introduce/club/intro.club.controller.ts | 21 +++++++++--- .../reservation.statistics.controller.ts | 26 +++++++++++++++ src/statistics/user.statistics.controller.ts | 33 +++++++++++++++++++ 4 files changed, 91 insertions(+), 10 deletions(-) diff --git a/src/popo/introduce/association/intro.association.controller.ts b/src/popo/introduce/association/intro.association.controller.ts index 746268b..4c05c4d 100644 --- a/src/popo/introduce/association/intro.association.controller.ts +++ b/src/popo/introduce/association/intro.association.controller.ts @@ -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'; @@ -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); @@ -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) diff --git a/src/popo/introduce/club/intro.club.controller.ts b/src/popo/introduce/club/intro.club.controller.ts index acfc5b0..87aed16 100644 --- a/src/popo/introduce/club/intro.club.controller.ts +++ b/src/popo/introduce/club/intro.club.controller.ts @@ -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'; @@ -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) { @@ -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); @@ -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) diff --git a/src/statistics/reservation.statistics.controller.ts b/src/statistics/reservation.statistics.controller.ts index 3120691..af38c12 100644 --- a/src/statistics/reservation.statistics.controller.ts +++ b/src/statistics/reservation.statistics.controller.ts @@ -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, + } + } } diff --git a/src/statistics/user.statistics.controller.ts b/src/statistics/user.statistics.controller.ts index 4629cd7..6920057 100644 --- a/src/statistics/user.statistics.controller.ts +++ b/src/statistics/user.statistics.controller.ts @@ -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, + } + } }