From 7818a1612ca2f10d72bb7c565ad1c99cd9e1a1db Mon Sep 17 00:00:00 2001 From: Conut-1 <1mim1@naver.com> Date: Thu, 14 Nov 2024 21:25:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=8B=9C=EA=B0=84=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/src/invite-codes/invite-codes.service.ts | 11 ++--------- nestjs-BE/server/src/utils/date.ts | 3 +++ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/nestjs-BE/server/src/invite-codes/invite-codes.service.ts b/nestjs-BE/server/src/invite-codes/invite-codes.service.ts index a6d51958..81931894 100644 --- a/nestjs-BE/server/src/invite-codes/invite-codes.service.ts +++ b/nestjs-BE/server/src/invite-codes/invite-codes.service.ts @@ -11,7 +11,7 @@ import { INVITE_CODE_LENGTH, } from '../config/magic-number'; import generateUuid from '../utils/uuid'; -import { checkExpiry } from '../utils/date'; +import { checkExpiry, getExpiryDate } from '../utils/date'; import { SpacesService } from '../spaces/spaces.service'; @Injectable() @@ -45,7 +45,7 @@ export class InviteCodesService { uuid: generateUuid(), inviteCode: await this.generateUniqueInviteCode(INVITE_CODE_LENGTH), spaceUuid: spaceUuid, - expiryDate: this.calculateExpiryDate(), + expiryDate: getExpiryDate({ hour: INVITE_CODE_EXPIRY_HOURS }), }, }); } @@ -66,13 +66,6 @@ export class InviteCodesService { } } - private calculateExpiryDate(): Date { - const currentDate = new Date(); - const expiryDate = new Date(currentDate); - expiryDate.setHours(currentDate.getHours() + INVITE_CODE_EXPIRY_HOURS); - return expiryDate; - } - private generateShortInviteCode(length: number) { const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; diff --git a/nestjs-BE/server/src/utils/date.ts b/nestjs-BE/server/src/utils/date.ts index de2f2451..bd210242 100644 --- a/nestjs-BE/server/src/utils/date.ts +++ b/nestjs-BE/server/src/utils/date.ts @@ -3,13 +3,16 @@ const WEEK_DAY = 7; export function getExpiryDate({ week = 0, day = 0, + hour = 0, }: { week?: number; day?: number; + hour?: number; }): Date { const expiryDate = new Date(); expiryDate.setDate(expiryDate.getDate() + week * WEEK_DAY + day); + expiryDate.setHours(expiryDate.getHours() + hour); return expiryDate; }