From af82f93f7755ffadbeddd242b32f7405be002d6d Mon Sep 17 00:00:00 2001 From: devleejb Date: Thu, 18 Jan 2024 11:04:01 +0900 Subject: [PATCH] Add service for retrieving a workspace --- backend/src/workspaces/workspaces.service.ts | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/backend/src/workspaces/workspaces.service.ts b/backend/src/workspaces/workspaces.service.ts index 913f2851..cd360b18 100644 --- a/backend/src/workspaces/workspaces.service.ts +++ b/backend/src/workspaces/workspaces.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from "@nestjs/common"; +import { Injectable, NotFoundException } from "@nestjs/common"; import { Workspace } from "@prisma/client"; import { PrismaService } from "src/db/prisma.service"; @@ -23,4 +23,23 @@ export class WorkspacesService { return workspace; } + + async findOne(userId: string, workspaceId: string) { + try { + await this.prismaService.userWorkspace.findFirstOrThrow({ + where: { + userId, + workspaceId, + }, + }); + } catch (e) { + throw new NotFoundException(); + } + + return await this.prismaService.workspace.findUnique({ + where: { + id: workspaceId, + }, + }); + } }