| 470 | } |
| 471 | |
| 472 | export async function createReference( |
| 473 | request: FastifyRequest<{ Body: z.infer<typeof zCreateReference> }>, |
| 474 | reply: FastifyReply |
| 475 | ) { |
| 476 | const { projectId, title, description, datetime } = request.body; |
| 477 | |
| 478 | // Verify project belongs to organization |
| 479 | const project = await db.project.findFirst({ |
| 480 | where: { |
| 481 | id: projectId, |
| 482 | organizationId: request.client!.organizationId, |
| 483 | }, |
| 484 | }); |
| 485 | |
| 486 | if (!project) { |
| 487 | throw new HttpError('Project not found', { status: 404 }); |
| 488 | } |
| 489 | |
| 490 | const reference = await db.reference.create({ |
| 491 | data: { |
| 492 | projectId, |
| 493 | title, |
| 494 | description: description || null, |
| 495 | date: new Date(datetime), |
| 496 | }, |
| 497 | }); |
| 498 | |
| 499 | reply.send({ data: reference }); |
| 500 | } |
| 501 | |
| 502 | export async function updateReference( |
| 503 | request: FastifyRequest<{ |