mirror of
https://github.com/documenso/documenso.git
synced 2026-08-16 03:21:55 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b0e31e054 | ||
|
|
7964784291 |
@@ -1,12 +1,9 @@
|
||||
import { getBaseUrl } from '@documenso/lib/universal/get-base-url';
|
||||
import { createTRPCClient, httpBatchLink, httpLink, isNonJsonSerializable, splitLink } from '@trpc/client';
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { AppRouter } from '../server/router';
|
||||
import { dataTransformer } from '../utils/data-transformer';
|
||||
|
||||
const ZTeamIdHeaderSchema = z.string().min(1);
|
||||
|
||||
export const trpc = createTRPCClient<AppRouter>({
|
||||
links: [
|
||||
splitLink({
|
||||
@@ -15,11 +12,9 @@ export const trpc = createTRPCClient<AppRouter>({
|
||||
url: `${getBaseUrl()}/api/trpc`,
|
||||
transformer: dataTransformer,
|
||||
headers: (opts) => {
|
||||
const teamId = ZTeamIdHeaderSchema.safeParse(opts.op.context.teamId);
|
||||
|
||||
if (teamId.success) {
|
||||
if (typeof opts.op.context.teamId === 'string') {
|
||||
return {
|
||||
'x-team-id': teamId.data,
|
||||
'x-team-id': opts.op.context.teamId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -30,14 +25,14 @@ export const trpc = createTRPCClient<AppRouter>({
|
||||
url: `${getBaseUrl()}/api/trpc`,
|
||||
transformer: dataTransformer,
|
||||
headers: (opts) => {
|
||||
for (const op of opts.opList) {
|
||||
const teamId = ZTeamIdHeaderSchema.safeParse(op.context.teamId);
|
||||
const operationWithTeamId = opts.opList.find(
|
||||
(op) => op.context.teamId && typeof op.context.teamId === 'string',
|
||||
);
|
||||
|
||||
if (teamId.success) {
|
||||
return {
|
||||
'x-team-id': teamId.data,
|
||||
};
|
||||
}
|
||||
if (operationWithTeamId && typeof operationWithTeamId.context.teamId === 'string') {
|
||||
return {
|
||||
'x-team-id': operationWithTeamId.context.teamId,
|
||||
};
|
||||
}
|
||||
|
||||
return {};
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-reques
|
||||
import { putPdfFileServerSide } from '@documenso/lib/universal/upload/put-file.server';
|
||||
import { EnvelopeType } from '@prisma/client';
|
||||
import type { Logger } from 'pino';
|
||||
import { match, P } from 'ts-pattern';
|
||||
|
||||
import { insertFormValuesInPdf } from '../../../lib/server-only/pdf/insert-form-values-in-pdf';
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
@@ -148,19 +149,11 @@ export const createEnvelopeRouteCaller = async ({
|
||||
accessAuth: recipient.accessAuth,
|
||||
actionAuth: recipient.actionAuth,
|
||||
fields: recipient.fields?.map((field) => {
|
||||
let documentDataId: string | undefined;
|
||||
|
||||
if (typeof field.identifier === 'string') {
|
||||
documentDataId = envelopeItems.find((item) => item.title === field.identifier)?.documentDataId;
|
||||
}
|
||||
|
||||
if (typeof field.identifier === 'number') {
|
||||
documentDataId = envelopeItems.at(field.identifier)?.documentDataId;
|
||||
}
|
||||
|
||||
if (field.identifier === undefined) {
|
||||
documentDataId = envelopeItems.at(0)?.documentDataId;
|
||||
}
|
||||
const documentDataId = match(field.identifier)
|
||||
.with(P.string, (title) => envelopeItems.find((item) => item.title === title)?.documentDataId)
|
||||
.with(P.number, (index) => envelopeItems.at(index)?.documentDataId)
|
||||
.with(undefined, () => envelopeItems.at(0)?.documentDataId)
|
||||
.exhaustive();
|
||||
|
||||
if (!documentDataId) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
|
||||
@@ -39,8 +39,8 @@ export const signEnvelopeFieldRoute = procedure
|
||||
const field = await prisma.field.findFirst({
|
||||
where: {
|
||||
id: fieldId,
|
||||
recipient: {
|
||||
...(recipient.role === RecipientRole.ASSISTANT
|
||||
recipient:
|
||||
recipient.role === RecipientRole.ASSISTANT
|
||||
? {
|
||||
signingStatus: {
|
||||
not: SigningStatus.SIGNED,
|
||||
@@ -52,8 +52,7 @@ export const signEnvelopeFieldRoute = procedure
|
||||
}
|
||||
: {
|
||||
id: recipient.id,
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
envelope: {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { createDocumentFromTemplate } from '@documenso/lib/server-only/template/
|
||||
import { putNormalizedPdfFileServerSide } from '@documenso/lib/universal/upload/put-file.server';
|
||||
import { formatSigningLink } from '@documenso/lib/utils/recipients';
|
||||
import { EnvelopeType } from '@prisma/client';
|
||||
import { match, P } from 'ts-pattern';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import { useEnvelopeMeta, ZUseEnvelopeRequestSchema, ZUseEnvelopeResponseSchema } from './use-envelope.types';
|
||||
@@ -87,20 +88,11 @@ export const useEnvelopeRoute = authenticatedProcedure
|
||||
|
||||
// Map custom document data using identifiers
|
||||
const customDocumentDataMapped = customDocumentData?.map((mapping) => {
|
||||
let documentDataId: string | undefined;
|
||||
|
||||
// Find the uploaded file by identifier
|
||||
if (typeof mapping.identifier === 'string') {
|
||||
documentDataId = uploadedFiles.find((file) => file.name === mapping.identifier)?.documentDataId;
|
||||
}
|
||||
|
||||
if (typeof mapping.identifier === 'number') {
|
||||
documentDataId = uploadedFiles.at(mapping.identifier)?.documentDataId;
|
||||
}
|
||||
|
||||
if (mapping.identifier === undefined) {
|
||||
documentDataId = uploadedFiles.at(0)?.documentDataId;
|
||||
}
|
||||
const documentDataId = match(mapping.identifier)
|
||||
.with(P.string, (name) => uploadedFiles.find((file) => file.name === name)?.documentDataId)
|
||||
.with(P.number, (index) => uploadedFiles.at(index)?.documentDataId)
|
||||
.exhaustive();
|
||||
|
||||
if (!documentDataId) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
|
||||
Reference in New Issue
Block a user