mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
## Description General enhancements for templates. ## Changes Made Added the following changes to the template flow: - Allow adding document meta settings - Allow adding email settings - Allow adding document access & action authentication - Allow adding recipient action authentication - Save the state between template steps similar to how it works for documents Other changes: - Extract common fields between document and template flows - Remove the title field from "Use template" since we now have it as part of the template flow - Add new API endpoint for generating templates ## Testing Performed Added E2E tests for templates and creating documents from templates
91 lines
2.1 KiB
TypeScript
91 lines
2.1 KiB
TypeScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
import { prisma } from '..';
|
|
import type { Prisma, User } from '../client';
|
|
import { DocumentDataType, ReadStatus, RecipientRole, SendStatus, SigningStatus } from '../client';
|
|
|
|
const examplePdf = fs
|
|
.readFileSync(path.join(__dirname, '../../../assets/example.pdf'))
|
|
.toString('base64');
|
|
|
|
type SeedTemplateOptions = {
|
|
title?: string;
|
|
userId: number;
|
|
teamId?: number;
|
|
};
|
|
|
|
type CreateTemplateOptions = {
|
|
key?: string | number;
|
|
createTemplateOptions?: Partial<Prisma.TemplateUncheckedCreateInput>;
|
|
};
|
|
|
|
export const seedBlankTemplate = async (owner: User, options: CreateTemplateOptions = {}) => {
|
|
const { key, createTemplateOptions = {} } = options;
|
|
|
|
const documentData = await prisma.documentData.create({
|
|
data: {
|
|
type: DocumentDataType.BYTES_64,
|
|
data: examplePdf,
|
|
initialData: examplePdf,
|
|
},
|
|
});
|
|
|
|
return await prisma.template.create({
|
|
data: {
|
|
title: `[TEST] Template ${key}`,
|
|
templateDocumentDataId: documentData.id,
|
|
userId: owner.id,
|
|
...createTemplateOptions,
|
|
},
|
|
});
|
|
};
|
|
|
|
export const seedTemplate = async (options: SeedTemplateOptions) => {
|
|
const { title = 'Untitled', userId, teamId } = options;
|
|
|
|
const documentData = await prisma.documentData.create({
|
|
data: {
|
|
type: DocumentDataType.BYTES_64,
|
|
data: examplePdf,
|
|
initialData: examplePdf,
|
|
},
|
|
});
|
|
|
|
return await prisma.template.create({
|
|
data: {
|
|
title,
|
|
templateDocumentData: {
|
|
connect: {
|
|
id: documentData.id,
|
|
},
|
|
},
|
|
User: {
|
|
connect: {
|
|
id: userId,
|
|
},
|
|
},
|
|
Recipient: {
|
|
create: {
|
|
email: 'recipient.1@documenso.com',
|
|
name: 'Recipient 1',
|
|
token: Math.random().toString().slice(2, 7),
|
|
sendStatus: SendStatus.NOT_SENT,
|
|
signingStatus: SigningStatus.NOT_SIGNED,
|
|
readStatus: ReadStatus.NOT_OPENED,
|
|
role: RecipientRole.SIGNER,
|
|
},
|
|
},
|
|
...(teamId
|
|
? {
|
|
team: {
|
|
connect: {
|
|
id: teamId,
|
|
},
|
|
},
|
|
}
|
|
: {}),
|
|
},
|
|
});
|
|
};
|