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

Function updateReference

apps/api/src/controllers/manage.controller.ts:502–552  ·  view source on GitHub ↗
(
  request: FastifyRequest<{
    Params: { id: string };
    Body: z.infer<typeof zUpdateReference>;
  }>,
  reply: FastifyReply
)

Source from the content-addressed store, hash-verified

500}
501
502export async function updateReference(
503 request: FastifyRequest<{
504 Params: { id: string };
505 Body: z.infer<typeof zUpdateReference>;
506 }>,
507 reply: FastifyReply
508) {
509 const body = request.body;
510
511 // Verify reference exists and belongs to organization
512 const existing = await db.reference.findUnique({
513 where: {
514 id: request.params.id,
515 },
516 include: {
517 project: {
518 select: {
519 organizationId: true,
520 },
521 },
522 },
523 });
524
525 if (!existing) {
526 throw new HttpError('Reference not found', { status: 404 });
527 }
528
529 if (existing.project.organizationId !== request.client!.organizationId) {
530 throw new HttpError('Reference not found', { status: 404 });
531 }
532
533 const updateData: any = {};
534 if (body.title !== undefined) {
535 updateData.title = body.title;
536 }
537 if (body.description !== undefined) {
538 updateData.description = body.description ?? null;
539 }
540 if (body.datetime !== undefined) {
541 updateData.date = new Date(body.datetime);
542 }
543
544 const reference = await db.reference.update({
545 where: {
546 id: request.params.id,
547 },
548 data: updateData,
549 });
550
551 reply.send({ data: reference });
552}
553
554export async function deleteReference(
555 request: FastifyRequest<{ Params: { id: string } }>,

Callers

nothing calls this directly

Calls 1

sendMethod · 0.45

Tested by

no test coverage detected