fix: refactor prisma relations (#1581)

This commit is contained in:
David Nguyen
2025-01-13 13:41:53 +11:00
committed by GitHub
parent 48b55758e3
commit 7d0a9c6439
143 changed files with 687 additions and 790 deletions

View File

@ -115,7 +115,7 @@ export const seedDraftDocument = async (
for (const recipient of recipients) {
const email = typeof recipient === 'string' ? recipient : recipient.email;
const name = typeof recipient === 'string' ? recipient : recipient.name ?? '';
const name = typeof recipient === 'string' ? recipient : (recipient.name ?? '');
await prisma.recipient.create({
data: {
@ -126,12 +126,12 @@ export const seedDraftDocument = async (
sendStatus: SendStatus.NOT_SENT,
signingStatus: SigningStatus.NOT_SIGNED,
signedAt: new Date(),
Document: {
document: {
connect: {
id: document.id,
},
},
Field: {
fields: {
create: {
page: 1,
type: FieldType.NAME,
@ -184,7 +184,7 @@ export const seedPendingDocument = async (
for (const recipient of recipients) {
const email = typeof recipient === 'string' ? recipient : recipient.email;
const name = typeof recipient === 'string' ? recipient : recipient.name ?? '';
const name = typeof recipient === 'string' ? recipient : (recipient.name ?? '');
await prisma.recipient.create({
data: {
@ -195,12 +195,12 @@ export const seedPendingDocument = async (
sendStatus: SendStatus.SENT,
signingStatus: SigningStatus.NOT_SIGNED,
signedAt: new Date(),
Document: {
document: {
connect: {
id: document.id,
},
},
Field: {
fields: {
create: {
page: 1,
type: FieldType.NAME,
@ -222,7 +222,7 @@ export const seedPendingDocument = async (
id: document.id,
},
include: {
Recipient: true,
recipients: true,
},
});
};
@ -240,7 +240,7 @@ export const seedPendingDocumentNoFields = async ({
for (const recipient of recipients) {
const email = typeof recipient === 'string' ? recipient : recipient.email;
const name = typeof recipient === 'string' ? recipient : recipient.name ?? '';
const name = typeof recipient === 'string' ? recipient : (recipient.name ?? '');
await prisma.recipient.create({
data: {
@ -251,7 +251,7 @@ export const seedPendingDocumentNoFields = async ({
sendStatus: SendStatus.SENT,
signingStatus: SigningStatus.NOT_SIGNED,
signedAt: new Date(),
Document: {
document: {
connect: {
id: document.id,
},
@ -265,7 +265,7 @@ export const seedPendingDocumentNoFields = async ({
documentId: document.id,
},
include: {
Field: true,
fields: true,
},
});
@ -301,7 +301,7 @@ export const seedPendingDocumentWithFullFields = async ({
for (const [recipientIndex, recipient] of recipients.entries()) {
const email = typeof recipient === 'string' ? recipient : recipient.email;
const name = typeof recipient === 'string' ? recipient : recipient.name ?? '';
const name = typeof recipient === 'string' ? recipient : (recipient.name ?? '');
await prisma.recipient.create({
data: {
@ -312,12 +312,12 @@ export const seedPendingDocumentWithFullFields = async ({
sendStatus: SendStatus.SENT,
signingStatus: SigningStatus.NOT_SIGNED,
signedAt: new Date(),
Document: {
document: {
connect: {
id: document.id,
},
},
Field: {
fields: {
createMany: {
data: fields.map((fieldType, fieldIndex) => ({
page: 1,
@ -342,7 +342,7 @@ export const seedPendingDocumentWithFullFields = async ({
documentId: document.id,
},
include: {
Field: true,
fields: true,
},
});
@ -393,7 +393,7 @@ export const seedCompletedDocument = async (
for (const recipient of recipients) {
const email = typeof recipient === 'string' ? recipient : recipient.email;
const name = typeof recipient === 'string' ? recipient : recipient.name ?? '';
const name = typeof recipient === 'string' ? recipient : (recipient.name ?? '');
await prisma.recipient.create({
data: {
@ -404,12 +404,12 @@ export const seedCompletedDocument = async (
sendStatus: SendStatus.SENT,
signingStatus: SigningStatus.SIGNED,
signedAt: new Date(),
Document: {
document: {
connect: {
id: document.id,
},
},
Field: {
fields: {
create: {
page: 1,
type: FieldType.NAME,

View File

@ -58,7 +58,7 @@ export const seedDatabase = async () => {
title: 'Example Document',
documentDataId: examplePdfData.id,
userId: exampleUser.id,
Recipient: {
recipients: {
create: {
name: String(adminUser.name),
email: adminUser.email,

View File

@ -66,12 +66,12 @@ export const seedTemplate = async (options: SeedTemplateOptions) => {
id: documentData.id,
},
},
User: {
user: {
connect: {
id: userId,
},
},
Recipient: {
recipients: {
create: {
email: 'recipient.1@documenso.com',
name: 'Recipient 1',
@ -114,12 +114,12 @@ export const seedDirectTemplate = async (options: SeedTemplateOptions) => {
id: documentData.id,
},
},
User: {
user: {
connect: {
id: userId,
},
},
Recipient: {
recipients: {
create: {
email: DIRECT_TEMPLATE_RECIPIENT_EMAIL,
name: DIRECT_TEMPLATE_RECIPIENT_NAME,
@ -138,12 +138,12 @@ export const seedDirectTemplate = async (options: SeedTemplateOptions) => {
...options.createTemplateOptions,
},
include: {
Recipient: true,
User: true,
recipients: true,
user: true,
},
});
const directTemplateRecpient = template.Recipient.find(
const directTemplateRecpient = template.recipients.find(
(recipient) => recipient.email === DIRECT_TEMPLATE_RECIPIENT_EMAIL,
);
@ -166,8 +166,8 @@ export const seedDirectTemplate = async (options: SeedTemplateOptions) => {
},
include: {
directLink: true,
Field: true,
Recipient: true,
fields: true,
recipients: true,
team: true,
},
});