| 335 | } |
| 336 | |
| 337 | export async function updateClient( |
| 338 | request: FastifyRequest<{ |
| 339 | Params: { id: string }; |
| 340 | Body: z.infer<typeof zUpdateClient>; |
| 341 | }>, |
| 342 | reply: FastifyReply |
| 343 | ) { |
| 344 | // Verify client exists and belongs to organization |
| 345 | const existing = await db.client.findFirst({ |
| 346 | where: { |
| 347 | id: request.params.id, |
| 348 | organizationId: request.client!.organizationId, |
| 349 | }, |
| 350 | }); |
| 351 | |
| 352 | if (!existing) { |
| 353 | throw new HttpError('Client not found', { status: 404 }); |
| 354 | } |
| 355 | |
| 356 | const updateData: any = {}; |
| 357 | if (request.body.name !== undefined) { |
| 358 | updateData.name = request.body.name; |
| 359 | } |
| 360 | |
| 361 | const client = await db.client.update({ |
| 362 | where: { |
| 363 | id: request.params.id, |
| 364 | }, |
| 365 | data: updateData, |
| 366 | }); |
| 367 | |
| 368 | await getClientByIdCached.clear(client.id); |
| 369 | |
| 370 | reply.send({ data: client }); |
| 371 | } |
| 372 | |
| 373 | export async function deleteClient( |
| 374 | request: FastifyRequest<{ Params: { id: string } }>, |