MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / getProjectId

Function getProjectId

apps/api/src/controllers/export.controller.ts:16–61  ·  view source on GitHub ↗
(
  request: FastifyRequest<{
    Querystring: {
      project_id?: string;
      projectId?: string;
    };
  }>
)

Source from the content-addressed store, hash-verified

14import { HttpError } from '@/utils/errors';
15
16async function getProjectId(
17 request: FastifyRequest<{
18 Querystring: {
19 project_id?: string;
20 projectId?: string;
21 };
22 }>
23) {
24 let projectId = request.query.projectId || request.query.project_id;
25
26 if (projectId) {
27 if (
28 request.client?.type === ClientType.read &&
29 request.client?.projectId !== projectId
30 ) {
31 throw new HttpError('You do not have access to this project', {
32 status: 403,
33 });
34 }
35
36 const project = await db.project.findUnique({
37 where: {
38 organizationId: request.client?.organizationId,
39 id: projectId,
40 },
41 });
42
43 if (!project) {
44 throw new HttpError('Project not found', {
45 status: 404,
46 });
47 }
48 }
49
50 if (!projectId && request.client?.projectId) {
51 projectId = request.client?.projectId;
52 }
53
54 if (!projectId) {
55 throw new HttpError('project_id or projectId is required', {
56 status: 400,
57 });
58 }
59
60 return projectId;
61}
62
63export const eventsScheme = z.object({
64 project_id: z.string().optional(),

Callers 2

eventsFunction · 0.70
chartsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected