From dab9499d88401eb4f812a69bbd9ee6d914fb9360 Mon Sep 17 00:00:00 2001 From: devleejb Date: Thu, 8 Feb 2024 16:48:57 +0900 Subject: [PATCH] Change file upload endpoint to public --- backend/src/files/files.controller.ts | 4 +--- backend/src/files/files.service.ts | 11 +++-------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/backend/src/files/files.controller.ts b/backend/src/files/files.controller.ts index a1490d2a..f4fa86e1 100644 --- a/backend/src/files/files.controller.ts +++ b/backend/src/files/files.controller.ts @@ -6,11 +6,11 @@ import { AuthroizedRequest } from "src/utils/types/req.type"; import { CreateUploadPresignedUrlDto } from "./dto/create-upload-url.dto"; import { Public } from "src/utils/decorators/auth.decorator"; -@ApiBearerAuth() @Controller("files") export class FilesController { constructor(private filesService: FilesService) {} + @Public() @Post("") @ApiOperation({ summary: "Create Presigned URL for Upload", @@ -19,12 +19,10 @@ export class FilesController { @ApiBody({ type: CreateUploadPresignedUrlDto }) @ApiResponse({ type: CreateUploadPresignedUrlResponse }) async createUploadPresignedUrl( - @Req() req: AuthroizedRequest, @Body() createUploadPresignedUrlDto: CreateUploadPresignedUrlDto ): Promise { return { url: await this.filesService.createUploadPresignedUrl( - req.user.id, createUploadPresignedUrlDto.workspaceId ), }; diff --git a/backend/src/files/files.service.ts b/backend/src/files/files.service.ts index 951f33ad..eb15019b 100644 --- a/backend/src/files/files.service.ts +++ b/backend/src/files/files.service.ts @@ -18,19 +18,14 @@ export class FilesService { this.s3Client = new S3Client(); } - async createUploadPresignedUrl(userId: string, workspaceId: string) { + async createUploadPresignedUrl(workspaceId: string) { let workspace: Workspace; try { - const userWorkspace = await this.prismaService.userWorkspace.findFirstOrThrow({ + workspace = await this.prismaService.workspace.findFirstOrThrow({ where: { - userId, - workspaceId, - }, - select: { - workspace: true, + id: workspaceId, }, }); - workspace = userWorkspace.workspace; } catch (e) { throw new UnauthorizedException(); }