fix: remove templateToken

This commit is contained in:
Mythie
2023-12-15 22:07:27 +11:00
parent 1eeb5fb103
commit 82da337a56
8 changed files with 22 additions and 17 deletions

View File

@ -86,6 +86,7 @@ export const SinglePlayerClient = () => {
data.fields.map((field, i) => ({
id: i,
documentId: -1,
templateId: null,
recipientId: -1,
type: field.type,
page: field.pageNumber,
@ -148,10 +149,10 @@ export const SinglePlayerClient = () => {
const placeholderRecipient: Recipient = {
id: -1,
documentId: -1,
templateId: null,
email: '',
name: '',
token: '',
templateToken: '',
expired: null,
signedAt: null,
readStatus: 'OPENED',

View File

@ -77,7 +77,6 @@ export const setRecipientsForTemplate = async ({
name: recipient.name,
email: recipient.email,
token: nanoid(),
templateToken: nanoid(),
templateId,
},
}),

View File

@ -1,6 +1,6 @@
import { nanoid } from '@documenso/lib/universal/id';
import { prisma } from '@documenso/prisma';
import { TCreateDocumentFromTemplateMutationSchema } from '@documenso/trpc/server/template-router/schema';
import type { TCreateDocumentFromTemplateMutationSchema } from '@documenso/trpc/server/template-router/schema';
export type CreateDocumentFromTemplateOptions = TCreateDocumentFromTemplateMutationSchema & {
userId: number;
@ -41,7 +41,6 @@ export const createDocumentFromTemplate = async ({
email: recipient.email,
name: recipient.name,
token: nanoid(),
templateToken: recipient.templateToken,
})),
},
},
@ -55,9 +54,7 @@ export const createDocumentFromTemplate = async ({
data: template.Field.map((field) => {
const recipient = template.Recipient.find((recipient) => recipient.id === field.recipientId);
const documentRecipient = document.Recipient.find(
(doc) => doc.templateToken === recipient?.templateToken,
);
const documentRecipient = document.Recipient.find((doc) => doc.email === recipient?.email);
return {
type: field.type,

View File

@ -1,6 +1,6 @@
import { nanoid } from '@documenso/lib/universal/id';
import { prisma } from '@documenso/prisma';
import { TDuplicateTemplateMutationSchema } from '@documenso/trpc/server/template-router/schema';
import type { TDuplicateTemplateMutationSchema } from '@documenso/trpc/server/template-router/schema';
export type DuplicateTemplateOptions = TDuplicateTemplateMutationSchema & {
userId: number;
@ -38,7 +38,6 @@ export const duplicateTemplate = async ({ templateId, userId }: DuplicateTemplat
email: recipient.email,
name: recipient.name,
token: nanoid(),
templateToken: recipient.templateToken,
})),
},
},
@ -53,7 +52,7 @@ export const duplicateTemplate = async ({ templateId, userId }: DuplicateTemplat
const recipient = template.Recipient.find((recipient) => recipient.id === field.recipientId);
const duplicatedTemplateRecipient = duplicatedTemplate.Recipient.find(
(doc) => doc.templateToken === recipient?.templateToken,
(doc) => doc.email === recipient?.email,
);
return {

View File

@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `templateToken` on the `Recipient` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Recipient" DROP COLUMN "templateToken";

View File

@ -188,7 +188,6 @@ model Recipient {
email String @db.VarChar(255)
name String @default("") @db.VarChar(255)
token String
templateToken String?
expired DateTime?
signedAt DateTime?
readStatus ReadStatus? @default(NOT_OPENED)
@ -272,14 +271,15 @@ enum TemplateType {
model Template {
id Int @id @default(autoincrement())
userId Int
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
title String
type TemplateType @default(PRIVATE)
title String
userId Int
templateDocumentDataId String
templateDocumentData DocumentData @relation(fields: [templateDocumentDataId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
templateDocumentData DocumentData @relation(fields: [templateDocumentDataId], references: [id], onDelete: Cascade)
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
Recipient Recipient[]
Field Field[]

View File

@ -63,6 +63,7 @@ export const singleplayerRouter = router({
// Dummy data.
id: -1,
documentId: -1,
templateId: null,
recipientId: -1,
});
}

View File

@ -89,7 +89,7 @@ export const AddTemplateFieldsFormPartial = ({
signerEmail:
recipients.find((recipient) => recipient.id === field.recipientId)?.email ?? '',
signerToken:
recipients.find((recipient) => recipient.id === field.recipientId)?.templateToken ?? '',
recipients.find((recipient) => recipient.id === field.recipientId)?.token ?? '',
})),
},
});
@ -187,7 +187,7 @@ export const AddTemplateFieldsFormPartial = ({
pageHeight: fieldPageHeight,
signerEmail: selectedSigner.email,
signerId: selectedSigner.id,
signerToken: selectedSigner.templateToken ?? '',
signerToken: selectedSigner.token ?? '',
});
setIsFieldWithinBounds(false);