From 6a36058ee6d38d6577c35bfcca7a1e45f40f3b16 Mon Sep 17 00:00:00 2001 From: space Date: Sat, 9 Dec 2023 03:45:57 +0900 Subject: [PATCH] feat: getAllTagPerMonth update features --- src/tag-log-v3/dto/UserInOutLogs.type.ts | 1 + .../dto/UserMonthlyInOutLogs.type.ts | 34 +++++++++++++++++++ src/tag-log-v3/tag-log-v3.controller.ts | 19 +++++++++-- src/utils/common.constants.ts | 2 ++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/tag-log-v3/dto/UserMonthlyInOutLogs.type.ts create mode 100644 src/utils/common.constants.ts diff --git a/src/tag-log-v3/dto/UserInOutLogs.type.ts b/src/tag-log-v3/dto/UserInOutLogs.type.ts index 0330af1..d3a4c68 100644 --- a/src/tag-log-v3/dto/UserInOutLogs.type.ts +++ b/src/tag-log-v3/dto/UserInOutLogs.type.ts @@ -19,4 +19,5 @@ export class UserInOutLogsType { type: [InOutLogType], }) inOutLogs: InOutLogType[]; + } diff --git a/src/tag-log-v3/dto/UserMonthlyInOutLogs.type.ts b/src/tag-log-v3/dto/UserMonthlyInOutLogs.type.ts new file mode 100644 index 0000000..dbe377a --- /dev/null +++ b/src/tag-log-v3/dto/UserMonthlyInOutLogs.type.ts @@ -0,0 +1,34 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { InOutLogType } from './subType/InOutLog.type'; + +export class UserMonthlyInOutLogsType { + @ApiProperty({ + description: '42 로그인 ID', + example: 'joopark', + }) + login: string; + + @ApiProperty({ + description: '인트라 이미지 URI', + example: 'https://cdn.intra.42.fr/users/joopark.jpg', + }) + profileImage: string; + + @ApiProperty({ + description: '입실 - 퇴실 정보 배열', + type: [InOutLogType], + }) + inOutLogs: InOutLogType[]; + + @ApiProperty({ + description: '월별 누적시간', + example: 12345, + }) + totalAccumulationTime: number | null = null; + + @ApiProperty({ + description: '월별 인정 누적시간', + example: 12345, + }) + acceptedAccumulationTime: number | null = null; +} diff --git a/src/tag-log-v3/tag-log-v3.controller.ts b/src/tag-log-v3/tag-log-v3.controller.ts index f2263b7..968d985 100644 --- a/src/tag-log-v3/tag-log-v3.controller.ts +++ b/src/tag-log-v3/tag-log-v3.controller.ts @@ -26,6 +26,8 @@ import { Cache } from 'cache-manager'; import { StatisticsService } from 'src/statistics/statictics.service'; import { CadetPerClusterDto } from 'src/statistics/dto/cadet-per-cluster.dto'; import { InOutLogPerDay, groupLogsByDay } from './dto/subType/InOutLogPerDay.type'; +import { UserMonthlyInOutLogsType } from './dto/UserMonthlyInOutLogs.type'; +import { TWELVE_HOURS_IN_SECONDS } from 'src/utils/common.constants'; @ApiTags('체류 시간 산출 v3') @Controller({ @@ -139,7 +141,7 @@ export class TagLogController { @User() user: UserSessionDto, @Query('year', ParseIntPipe) year: number, @Query('month', ParseIntPipe) month: number, - ): Promise { + ): Promise { this.logger.debug(`@getAllTagPerMonth) ${year}-${month} by ${user.login}`); const date = new Date(`${year}-${month}`); @@ -148,10 +150,23 @@ export class TagLogController { user.user_id, date, ); + const monthlyAccumulationTime = results.reduce( + (prev, result) => result.durationSecond + prev, 0, + ); + + const InOutLogPerDays: InOutLogPerDay[] = groupLogsByDay(results, TWELVE_HOURS_IN_SECONDS); + + const twelveHoursInSeconds = TWELVE_HOURS_IN_SECONDS; + const filteredMonthlyAccumulationTime = InOutLogPerDays.reduce( + (prev, result) => result.getDurationSecondWithFilter(twelveHoursInSeconds) + prev, 0, + ); + return { login: user.login, profileImage: user.image_url, inOutLogs: results, + totalAccumulationTime: monthlyAccumulationTime, + acceptedAccumulationTime: filteredMonthlyAccumulationTime, }; } @@ -230,7 +245,7 @@ export class TagLogController { date, ); //todo: change to all tag (and check plus null value) - const twelveHoursInSeconds = 12 * 60 * 60; + const twelveHoursInSeconds = TWELVE_HOURS_IN_SECONDS; const resultPerDay : InOutLogPerDay[] = groupLogsByDay(resultMonth, twelveHoursInSeconds); // 하루 최대 인정시간 합 diff --git a/src/utils/common.constants.ts b/src/utils/common.constants.ts new file mode 100644 index 0000000..8e03058 --- /dev/null +++ b/src/utils/common.constants.ts @@ -0,0 +1,2 @@ +export const TWELVE_HOURS_IN_SECONDS = 12 * 60 * 60; +export const ONE_DAY_IN_SECONDS = 24 * 60 * 60; \ No newline at end of file