(
request: FastifyRequest<{
Params: { id: string };
Body: z.infer<typeof zUpdateProject>;
}>,
reply: FastifyReply
)
| 148 | } |
| 149 | |
| 150 | export async function updateProject( |
| 151 | request: FastifyRequest<{ |
| 152 | Params: { id: string }; |
| 153 | Body: z.infer<typeof zUpdateProject>; |
| 154 | }>, |
| 155 | reply: FastifyReply |
| 156 | ) { |
| 157 | const body = request.body; |
| 158 | |
| 159 | // Verify project exists and belongs to organization |
| 160 | const existing = await db.project.findFirst({ |
| 161 | where: { |
| 162 | id: request.params.id, |
| 163 | organizationId: request.client!.organizationId, |
| 164 | }, |
| 165 | include: { |
| 166 | clients: { |
| 167 | select: { |
| 168 | id: true, |
| 169 | }, |
| 170 | }, |
| 171 | }, |
| 172 | }); |
| 173 | |
| 174 | if (!existing) { |
| 175 | throw new HttpError('Project not found', { status: 404 }); |
| 176 | } |
| 177 | |
| 178 | const updateData: any = {}; |
| 179 | if (body.name !== undefined) { |
| 180 | updateData.name = body.name; |
| 181 | } |
| 182 | if (body.domain !== undefined) { |
| 183 | updateData.domain = body.domain |
| 184 | ? stripTrailingSlash(body.domain) |
| 185 | : null; |
| 186 | } |
| 187 | if (body.cors !== undefined) { |
| 188 | updateData.cors = body.cors.map((c) => stripTrailingSlash(c)); |
| 189 | } |
| 190 | if (body.crossDomain !== undefined) { |
| 191 | updateData.crossDomain = body.crossDomain; |
| 192 | } |
| 193 | if (body.allowUnsafeRevenueTracking !== undefined) { |
| 194 | updateData.allowUnsafeRevenueTracking = body.allowUnsafeRevenueTracking; |
| 195 | } |
| 196 | |
| 197 | const project = await db.project.update({ |
| 198 | where: { |
| 199 | id: request.params.id, |
| 200 | }, |
| 201 | data: updateData, |
| 202 | }); |
| 203 | |
| 204 | await Promise.all([ |
| 205 | getProjectByIdCached.clear(project.id), |
| 206 | ...existing.clients.map((client) => getClientByIdCached.clear(client.id)), |
| 207 | ]); |
nothing calls this directly
no test coverage detected