({ request, params }: LoaderFunctionArgs)
| 11 | }); |
| 12 | |
| 13 | export async function loader({ request, params }: LoaderFunctionArgs) { |
| 14 | logger.info("get project", { url: request.url }); |
| 15 | |
| 16 | const authenticationResult = await authenticateApiRequestWithPersonalAccessToken(request); |
| 17 | |
| 18 | if (!authenticationResult) { |
| 19 | return json({ error: "Invalid or Missing Access Token" }, { status: 401 }); |
| 20 | } |
| 21 | |
| 22 | const parsedParams = ParamsSchema.safeParse(params); |
| 23 | |
| 24 | if (!parsedParams.success) { |
| 25 | return json({ error: "Invalid Params" }, { status: 400 }); |
| 26 | } |
| 27 | |
| 28 | const { projectRef } = parsedParams.data; |
| 29 | |
| 30 | const project = await prisma.project.findUnique({ |
| 31 | where: { |
| 32 | externalRef: projectRef, |
| 33 | organization: { |
| 34 | deletedAt: null, |
| 35 | members: { |
| 36 | some: { |
| 37 | userId: authenticationResult.userId, |
| 38 | }, |
| 39 | }, |
| 40 | }, |
| 41 | deletedAt: null, |
| 42 | }, |
| 43 | include: { |
| 44 | organization: true, |
| 45 | }, |
| 46 | }); |
| 47 | |
| 48 | if (!project) { |
| 49 | return json({ error: "Project not found" }, { status: 404 }); |
| 50 | } |
| 51 | |
| 52 | if (project.version !== "V3") { |
| 53 | return json({ error: "Project found but was not a v3 project" }, { status: 404 }); |
| 54 | } |
| 55 | |
| 56 | const result: GetProjectResponseBody = { |
| 57 | id: project.id, |
| 58 | externalRef: project.externalRef, |
| 59 | name: project.name, |
| 60 | slug: project.slug, |
| 61 | createdAt: project.createdAt, |
| 62 | organization: { |
| 63 | id: project.organization.id, |
| 64 | title: project.organization.title, |
| 65 | slug: project.organization.slug, |
| 66 | createdAt: project.organization.createdAt, |
| 67 | }, |
| 68 | }; |
| 69 | |
| 70 | return json(result); |
nothing calls this directly
no test coverage detected
searching dependent graphs…