Skip to content

Commit

Permalink
refactor: ♻️ 클러스터의 오픈일 상수 추가, 현재 시간을 반환하는 함수 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
niamu01 committed Jul 9, 2024
1 parent 9a72b29 commit 01c0a4b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/external/where42/where42.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import Cluster from 'src/enums/cluster.enum';
import { ITagLogRepository } from 'src/tag-log/repository/interface/tag-log-repository.interface';
import { IdLoginDto } from 'src/user/dto/id-login.dto';
import { UserService } from 'src/user/user.service';
import {
DateCalculator,
START_DATE,
} from 'src/utils/data-calculator/date-calculator.component';
import { Where42ResponseDto } from './dto/where42.response.dto';
import { IDeviceInfoRepository } from './repository/interface/device-info.repository.interface';

Expand All @@ -24,6 +28,7 @@ export class Where42Service {
private deviceInfoRepository: IDeviceInfoRepository,
@Inject('ITagLogRepository')
private tagLogRepository: ITagLogRepository,
private dateCalculator: DateCalculator,
) {}

async where42(login: string): Promise<Where42ResponseDto> {
Expand All @@ -37,8 +42,8 @@ export class Where42Service {

const cards = await this.userService.findCardsByUserId(
user_id,
new Date('2019-01-01 00:00:00'),
new Date(), // NOTE: 대략 42 클러스터 오픈일부터 지금까지 조회
START_DATE,
this.dateCalculator.getCurrentDate(),
);
const last = await this.tagLogRepository.findLatestTagLog(cards);
if (last === null) {
Expand Down Expand Up @@ -78,8 +83,8 @@ export class Where42Service {

const cards = await this.userService.findCardsByUserId(
user.user_id,
new Date('2019-01-01 00:00:00'),
new Date(), // NOTE: 대략 42 클러스터 오픈일부터 지금까지 조회
START_DATE,
this.dateCalculator.getCurrentDate(),
);

const last = await this.tagLogRepository.findLatestTagLog(cards);
Expand Down
9 changes: 6 additions & 3 deletions src/tag-log/tag-log.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import InOut from 'src/enums/inout.enum';
import { StatisticsService } from 'src/statistics/statistics.service';
import { CardDto } from 'src/user/dto/card.dto';
import { UserService } from 'src/user/user.service';
import { DateCalculator } from 'src/utils/data-calculator/date-calculator.component';
import {
DateCalculator,
START_DATE,
} from 'src/utils/data-calculator/date-calculator.component';
import { DeviceInfoDto } from './dto/device-info.dto';
import { InOutDto } from './dto/inout.dto';
import { PairInfoDto } from './dto/pair-info.dto';
Expand Down Expand Up @@ -555,8 +558,8 @@ export class TagLogService {
this.logger.debug(`@checkClusterById) ${userId}`);
const cards = await this.userService.findCardsByUserId(
userId,
new Date('2019-01-01 00:00:00'),
new Date(), // NOTE: 대략 42 클러스터 오픈일부터 지금까지 조회
START_DATE,
this.dateCalculator.getCurrentDate(),
);
const last = await this.tagLogRepository.findLatestTagLog(cards);
const inCards = await this.pairInfoRepository.findInGates();
Expand Down
10 changes: 10 additions & 0 deletions src/utils/data-calculator/date-calculator.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const HALF_DAY = HOUR * 24;
const DAY = HOUR * 24;
const WEEK = DAY * 7;

// NOTE: 42 클러스터의 대략적인 오픈일
export const START_DATE = new Date('2019-01-01T00:00:00Z');

/**
* 날짜/시간 관련 연산을 하기 위한 모듈입니다.
*/
Expand Down Expand Up @@ -172,6 +175,13 @@ export class DateCalculator {
return DAY / SEC;
}

/**
* @returns 현재 시간을 반환합니다.
*/
getCurrentDate(): Date {
return new Date();
}

/**
* @param durationPerday 하루에 있었던 체류시간 (초 단위)
* @returns 하루 단위로 초를 계산하여 12시간으로 나눈 나머지
Expand Down

0 comments on commit 01c0a4b

Please sign in to comment.