| 552 | } |
| 553 | |
| 554 | export async function deleteReference( |
| 555 | request: FastifyRequest<{ Params: { id: string } }>, |
| 556 | reply: FastifyReply |
| 557 | ) { |
| 558 | const reference = await db.reference.findUnique({ |
| 559 | where: { |
| 560 | id: request.params.id, |
| 561 | }, |
| 562 | include: { |
| 563 | project: { |
| 564 | select: { |
| 565 | organizationId: true, |
| 566 | }, |
| 567 | }, |
| 568 | }, |
| 569 | }); |
| 570 | |
| 571 | if (!reference) { |
| 572 | throw new HttpError('Reference not found', { status: 404 }); |
| 573 | } |
| 574 | |
| 575 | if (reference.project.organizationId !== request.client!.organizationId) { |
| 576 | throw new HttpError('Reference not found', { status: 404 }); |
| 577 | } |
| 578 | |
| 579 | await db.reference.delete({ |
| 580 | where: { |
| 581 | id: request.params.id, |
| 582 | }, |
| 583 | }); |
| 584 | |
| 585 | reply.send({ success: true }); |
| 586 | } |