From e49db6cfd0a9d085fe71047837f1d23c8abca99e Mon Sep 17 00:00:00 2001 From: Conut-1 <1mim1@naver.com> Date: Tue, 24 Dec 2024 23:16:08 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=EC=9D=84=20=EC=A0=9C=EA=B1=B0=ED=95=98=EA=B3=A0,=20cr?= =?UTF-8?q?eate=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/invite-codes/invite-codes.service.ts | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 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 b55c9082..8c34e949 100644 --- a/nestjs-BE/server/src/invite-codes/invite-codes.service.ts +++ b/nestjs-BE/server/src/invite-codes/invite-codes.service.ts @@ -35,22 +35,25 @@ export class InviteCodesService { } async createInviteCode(spaceUuid: string): Promise { - return this.prisma.$transaction(async () => { - let inviteCode: string; + let inviteCode: InviteCode; + const newUuid = uuid(); - do { - inviteCode = generateRandomString(INVITE_CODE_LENGTH); - } while (await this.findInviteCode(inviteCode)); + do { + try { + inviteCode = await this.prisma.inviteCode.create({ + data: { + uuid: newUuid, + inviteCode: generateRandomString(INVITE_CODE_LENGTH), + spaceUuid, + expiryDate: getExpiryDate({ hour: INVITE_CODE_EXPIRY_HOURS }), + }, + }); + } catch (err) { + if (err.code !== 'P2002') throw err; + } + } while (!inviteCode); - return this.prisma.inviteCode.create({ - data: { - uuid: uuid(), - inviteCode, - spaceUuid, - expiryDate: getExpiryDate({ hour: INVITE_CODE_EXPIRY_HOURS }), - }, - }); - }); + return inviteCode; } @Cron(CronExpression.EVERY_HOUR) From cd2266117d0ae45cf9e0ed66e657ed9e5a243bff Mon Sep 17 00:00:00 2001 From: Conut-1 <1mim1@naver.com> Date: Thu, 26 Dec 2024 16:50:24 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/src/invite-codes/invite-codes.service.spec.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/nestjs-BE/server/src/invite-codes/invite-codes.service.spec.ts b/nestjs-BE/server/src/invite-codes/invite-codes.service.spec.ts index 026f8a99..e6735dd7 100644 --- a/nestjs-BE/server/src/invite-codes/invite-codes.service.spec.ts +++ b/nestjs-BE/server/src/invite-codes/invite-codes.service.spec.ts @@ -87,10 +87,6 @@ describe('InviteCodesService', () => { const testInviteCode = { inviteCode: 'test invite code' } as InviteCode; beforeEach(() => { - (prisma.$transaction as jest.Mock) = jest.fn(async (callback) => - callback(), - ); - jest.spyOn(inviteCodesService, 'findInviteCode').mockResolvedValue(null); (prisma.inviteCode.create as jest.Mock) = jest.fn( async () => testInviteCode, ); @@ -100,7 +96,7 @@ describe('InviteCodesService', () => { const inviteCode = inviteCodesService.createInviteCode(testSpaceUuid); await expect(inviteCode).resolves.toEqual(testInviteCode); - expect(inviteCodesService.findInviteCode).toHaveBeenCalledTimes(1); + expect(prisma.inviteCode.create).toHaveBeenCalledTimes(1); }); }); }); From 8a622757ac94bd3bce2ac9774b8f610efbb98ef0 Mon Sep 17 00:00:00 2001 From: Conut-1 <1mim1@naver.com> Date: Mon, 30 Dec 2024 16:16:47 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20swagger=EC=97=90=20unauthorized?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=20=EC=A0=95=EB=B3=B4=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.controller.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nestjs-BE/server/src/invite-codes/invite-codes.controller.ts b/nestjs-BE/server/src/invite-codes/invite-codes.controller.ts index 312572c2..a0796bcc 100644 --- a/nestjs-BE/server/src/invite-codes/invite-codes.controller.ts +++ b/nestjs-BE/server/src/invite-codes/invite-codes.controller.ts @@ -30,6 +30,10 @@ export class InviteCodesController { status: HttpStatus.BAD_REQUEST, description: 'Space code input is missing.', }) + @ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: 'need access token', + }) @ApiResponse({ status: HttpStatus.NOT_FOUND, description: 'Space not found.', @@ -50,6 +54,10 @@ export class InviteCodesController { status: HttpStatus.OK, description: 'Returns a space associated with the invite code.', }) + @ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: 'need access token', + }) @ApiResponse({ status: HttpStatus.NOT_FOUND, description: 'Invite code not found.',