| 442 | } |
| 443 | |
| 444 | export async function getReference( |
| 445 | request: FastifyRequest<{ Params: { id: string } }>, |
| 446 | reply: FastifyReply |
| 447 | ) { |
| 448 | const reference = await db.reference.findUnique({ |
| 449 | where: { |
| 450 | id: request.params.id, |
| 451 | }, |
| 452 | include: { |
| 453 | project: { |
| 454 | select: { |
| 455 | organizationId: true, |
| 456 | }, |
| 457 | }, |
| 458 | }, |
| 459 | }); |
| 460 | |
| 461 | if (!reference) { |
| 462 | throw new HttpError('Reference not found', { status: 404 }); |
| 463 | } |
| 464 | |
| 465 | if (reference.project.organizationId !== request.client!.organizationId) { |
| 466 | throw new HttpError('Reference not found', { status: 404 }); |
| 467 | } |
| 468 | |
| 469 | reply.send({ data: reference }); |
| 470 | } |
| 471 | |
| 472 | export async function createReference( |
| 473 | request: FastifyRequest<{ Body: z.infer<typeof zCreateReference> }>, |