mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 00:32:43 +10:00
feat: add attachments (#2091)
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
import { EnvelopeType } from '@prisma/client';
|
||||
|
||||
import { findAttachmentsByEnvelopeId } from '@documenso/lib/server-only/envelope-attachment/find-attachments-by-envelope-id';
|
||||
import { getEnvelopeById } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZFindAttachmentsRequestSchema,
|
||||
ZFindAttachmentsResponseSchema,
|
||||
} from './find-attachments.types';
|
||||
|
||||
export const findAttachmentsRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'GET',
|
||||
path: '/document/attachment',
|
||||
summary: 'Find attachments',
|
||||
description: 'Find all attachments for a document',
|
||||
tags: ['Document'],
|
||||
},
|
||||
})
|
||||
.input(ZFindAttachmentsRequestSchema)
|
||||
.output(ZFindAttachmentsResponseSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { documentId } = input;
|
||||
const { teamId } = ctx;
|
||||
const userId = ctx.user.id;
|
||||
|
||||
ctx.logger.info({
|
||||
input: { documentId },
|
||||
});
|
||||
|
||||
const envelope = await getEnvelopeById({
|
||||
id: {
|
||||
type: 'documentId',
|
||||
id: documentId,
|
||||
},
|
||||
userId,
|
||||
teamId,
|
||||
type: EnvelopeType.DOCUMENT,
|
||||
});
|
||||
|
||||
const data = await findAttachmentsByEnvelopeId({
|
||||
envelopeId: envelope.id,
|
||||
teamId,
|
||||
userId,
|
||||
});
|
||||
|
||||
return {
|
||||
data,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user