mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
## Description Direct templates links is a feature that provides template owners the ability to allow users to create documents based of their templates. ## General outline This works by allowing the template owner to configure a "direct recipient" in the template. When a user opens the direct link to the template, it will create a flow where they sign the fields configured by the template owner for the direct recipient. After these fields are signed the following will occur: - A document will be created where the owner is the template owner - The direct recipient fields will be signed - The document will be sent to any other recipients configured in the template - If there are none the document will be immediately completed ## Notes There's a custom prisma migration to migrate all documents to have 'DOCUMENT' as the source, then sets the column to required. --------- Co-authored-by: Lucas Smith <me@lucasjamessmith.me>
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
import { hashSync } from '@documenso/lib/server-only/auth/hash';
|
|
|
|
import { prisma } from '..';
|
|
import { DocumentDataType, DocumentSource, Role } from '../client';
|
|
|
|
export const seedDatabase = async () => {
|
|
const examplePdf = fs
|
|
.readFileSync(path.join(__dirname, '../../../assets/example.pdf'))
|
|
.toString('base64');
|
|
|
|
const exampleUser = await prisma.user.upsert({
|
|
where: {
|
|
email: 'example@documenso.com',
|
|
},
|
|
create: {
|
|
name: 'Example User',
|
|
email: 'example@documenso.com',
|
|
emailVerified: new Date(),
|
|
password: hashSync('password'),
|
|
roles: [Role.USER],
|
|
},
|
|
update: {},
|
|
});
|
|
|
|
const adminUser = await prisma.user.upsert({
|
|
where: {
|
|
email: 'admin@documenso.com',
|
|
},
|
|
create: {
|
|
name: 'Admin User',
|
|
email: 'admin@documenso.com',
|
|
emailVerified: new Date(),
|
|
password: hashSync('password'),
|
|
roles: [Role.USER, Role.ADMIN],
|
|
},
|
|
update: {},
|
|
});
|
|
|
|
const examplePdfData = await prisma.documentData.upsert({
|
|
where: {
|
|
id: 'clmn0kv5k0000pe04vcqg5zla',
|
|
},
|
|
create: {
|
|
id: 'clmn0kv5k0000pe04vcqg5zla',
|
|
type: DocumentDataType.BYTES_64,
|
|
data: examplePdf,
|
|
initialData: examplePdf,
|
|
},
|
|
update: {},
|
|
});
|
|
|
|
await prisma.document.create({
|
|
data: {
|
|
source: DocumentSource.DOCUMENT,
|
|
title: 'Example Document',
|
|
documentDataId: examplePdfData.id,
|
|
userId: exampleUser.id,
|
|
Recipient: {
|
|
create: {
|
|
name: String(adminUser.name),
|
|
email: adminUser.email,
|
|
token: Math.random().toString(36).slice(2, 9),
|
|
},
|
|
},
|
|
},
|
|
});
|
|
};
|