Skip to content

Commit

Permalink
Merge pull request #46 from gsainfoteam/41-psw
Browse files Browse the repository at this point in the history
초대 코드의 만료시간 추가
  • Loading branch information
siwonpada authored Aug 24, 2024
2 parents 12c8491 + f528556 commit a99c807
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/group/group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,13 @@ export class GroupController {
summary: 'Join a group',
description: '그룹에 가입하는 API 입니다.',
})
@ApiCreatedResponse()
@ApiForbiddenResponse()
@ApiCreatedResponse({
description: '그룹에 성공적으로 가입되었습니다.',
})
@ApiForbiddenResponse({
description:
'옳지 않은 초대 코드입니다. 초대 코드가 만료되었거나, 존재하지 않습니다.',
})
@ApiInternalServerErrorResponse()
@Post('join')
async joinGroup(@Body() body: JoinDto, @GetUser() user: User): Promise<void> {
Expand Down
17 changes: 14 additions & 3 deletions src/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ExpandedGroup } from './types/ExpandedGroup.type';
@Injectable()
export class GroupService {
private readonly logger = new Logger(GroupService.name);
private readonly inviteCodePrefix = 'inviteCode';
private readonly invitationCodePrefix = 'invitationCode';
constructor(
private readonly groupRepository: GroupRepository,
@InjectRedis() private readonly redis: Redis,
Expand Down Expand Up @@ -52,6 +52,12 @@ export class GroupService {
await this.groupRepository.deleteGroup(uuid);
}

/**
* this method creates an invite code for a group, and the expiration time is 14 days.
* @param uuid uuid of the group
* @param userUuid uuid of the user who is creating the invite code
* @returns the invite code
*/
async createInviteCode(
uuid: string,
userUuid: string,
Expand All @@ -72,13 +78,18 @@ export class GroupService {
.randomBytes(32)
.toString('base64')
.replace(/[+\/=]/g, '');
await this.redis.set(`${this.inviteCodePrefix}:${code}`, uuid);
await this.redis.set(
`${this.invitationCodePrefix}:${code}`,
uuid,
'EX',
14 * 24 * 60 * 60,
);
return { code };
}

async joinMember(code: string, userUuid: string): Promise<void> {
this.logger.log(`updateMember: ${code}`);
const uuid = await this.redis.get(`${this.inviteCodePrefix}:${code}`);
const uuid = await this.redis.get(`${this.invitationCodePrefix}:${code}`);
if (!uuid) {
throw new ForbiddenException('Invalid invite code');
}
Expand Down

0 comments on commit a99c807

Please sign in to comment.