mirror of
https://github.com/documenso/documenso.git
synced 2026-08-25 07:42:28 +10:00
feat: render signatures on pending envelopes (#2743)
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { FieldType } from '@prisma/client';
|
||||
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { getEnvelopeWhereInput } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZGetEnvelopeFieldSignaturesRequestSchema,
|
||||
ZGetEnvelopeFieldSignaturesResponseSchema,
|
||||
} from './get-envelope-field-signatures.types';
|
||||
|
||||
export const getEnvelopeFieldSignaturesRoute = authenticatedProcedure
|
||||
.input(ZGetEnvelopeFieldSignaturesRequestSchema)
|
||||
.output(ZGetEnvelopeFieldSignaturesResponseSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { teamId, user } = ctx;
|
||||
const { envelopeId } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeId,
|
||||
},
|
||||
});
|
||||
|
||||
// Validate the user has access to the envelope.
|
||||
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
id: envelopeId,
|
||||
},
|
||||
type: null,
|
||||
userId: user.id,
|
||||
teamId,
|
||||
});
|
||||
|
||||
const envelope = await prisma.envelope.findFirst({
|
||||
where: envelopeWhereInput,
|
||||
include: {
|
||||
fields: {
|
||||
where: {
|
||||
inserted: true,
|
||||
type: FieldType.SIGNATURE,
|
||||
},
|
||||
include: {
|
||||
signature: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!envelope) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Envelope not found',
|
||||
});
|
||||
}
|
||||
|
||||
const signatures = envelope.fields.map((field) => ({
|
||||
fieldId: field.id,
|
||||
signatureImageAsBase64: field.signature?.signatureImageAsBase64 ?? null,
|
||||
typedSignature: field.signature?.typedSignature ?? null,
|
||||
}));
|
||||
|
||||
return signatures;
|
||||
});
|
||||
Reference in New Issue
Block a user