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

Function createProject

apps/api/src/controllers/manage.controller.ts:93–148  ·  view source on GitHub ↗
(
  request: FastifyRequest<{ Body: z.infer<typeof zCreateProject> }>,
  reply: FastifyReply
)

Source from the content-addressed store, hash-verified

91}
92
93export async function createProject(
94 request: FastifyRequest<{ Body: z.infer<typeof zCreateProject> }>,
95 reply: FastifyReply
96) {
97 const { name, domain, cors, crossDomain, types } = request.body;
98
99 // Generate a default client secret
100 const secret = `sec_${crypto.randomBytes(10).toString('hex')}`;
101 const clientData = {
102 organizationId: request.client!.organizationId,
103 name: 'First client',
104 type: 'write' as const,
105 secret: await hashPassword(secret),
106 };
107
108 const project = await db.project.create({
109 data: {
110 id: await getId('project', name),
111 organizationId: request.client!.organizationId,
112 name,
113 domain: domain ? stripTrailingSlash(domain) : null,
114 cors: cors.map((c) => stripTrailingSlash(c)),
115 crossDomain: crossDomain ?? false,
116 allowUnsafeRevenueTracking: false,
117 filters: [],
118 types,
119 clients: {
120 create: clientData,
121 },
122 },
123 include: {
124 clients: {
125 select: {
126 id: true,
127 },
128 },
129 },
130 });
131
132 await Promise.all([
133 getProjectByIdCached.clear(project.id),
134 ...project.clients.map((client) => getClientByIdCached.clear(client.id)),
135 ]);
136
137 reply.send({
138 data: {
139 ...project,
140 client: project.clients[0]
141 ? {
142 id: project.clients[0].id,
143 secret,
144 }
145 : null,
146 },
147 });
148}
149
150export async function updateProject(

Callers

nothing calls this directly

Calls 7

hashPasswordFunction · 0.90
getIdFunction · 0.90
stripTrailingSlashFunction · 0.90
toStringMethod · 0.45
mapMethod · 0.45
clearMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected