Skip to content

Commit

Permalink
feat: 시간 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Conut-1 committed Nov 14, 2024
1 parent 08b7b2d commit 7818a16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
11 changes: 2 additions & 9 deletions nestjs-BE/server/src/invite-codes/invite-codes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 }),
},
});
}
Expand All @@ -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';
Expand Down
3 changes: 3 additions & 0 deletions nestjs-BE/server/src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 7818a16

Please sign in to comment.