Skip to content

Commit

Permalink
feat: getAllTagPerMonth update features
Browse files Browse the repository at this point in the history
  • Loading branch information
enaenen committed Dec 8, 2023
1 parent bb747a3 commit 6a36058
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/tag-log-v3/dto/UserInOutLogs.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export class UserInOutLogsType {
type: [InOutLogType],
})
inOutLogs: InOutLogType[];

}
34 changes: 34 additions & 0 deletions src/tag-log-v3/dto/UserMonthlyInOutLogs.type.ts
Original file line number Diff line number Diff line change
@@ -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;
}
19 changes: 17 additions & 2 deletions src/tag-log-v3/tag-log-v3.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -139,7 +141,7 @@ export class TagLogController {
@User() user: UserSessionDto,
@Query('year', ParseIntPipe) year: number,
@Query('month', ParseIntPipe) month: number,
): Promise<UserInOutLogsType> {
): Promise<UserMonthlyInOutLogsType> {
this.logger.debug(`@getAllTagPerMonth) ${year}-${month} by ${user.login}`);

const date = new Date(`${year}-${month}`);
Expand All @@ -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,
};
}

Expand Down Expand Up @@ -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);

// 하루 최대 인정시간 합
Expand Down
2 changes: 2 additions & 0 deletions src/utils/common.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const TWELVE_HOURS_IN_SECONDS = 12 * 60 * 60;
export const ONE_DAY_IN_SECONDS = 24 * 60 * 60;

0 comments on commit 6a36058

Please sign in to comment.