mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +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>
69 lines
1.3 KiB
TypeScript
69 lines
1.3 KiB
TypeScript
import { customAlphabet } from 'nanoid';
|
|
|
|
import { hashSync } from '@documenso/lib/server-only/auth/hash';
|
|
|
|
import { prisma } from '..';
|
|
|
|
type SeedUserOptions = {
|
|
name?: string;
|
|
email?: string;
|
|
password?: string;
|
|
verified?: boolean;
|
|
};
|
|
|
|
const nanoid = customAlphabet('1234567890abcdef', 10);
|
|
|
|
export const seedTestEmail = () => `${nanoid()}@test.documenso.com`;
|
|
|
|
export const seedUser = async ({
|
|
name,
|
|
email,
|
|
password = 'password',
|
|
verified = true,
|
|
}: SeedUserOptions = {}) => {
|
|
if (!name) {
|
|
name = nanoid();
|
|
}
|
|
|
|
if (!email) {
|
|
email = `${nanoid()}@test.documenso.com`;
|
|
}
|
|
|
|
return await prisma.user.create({
|
|
data: {
|
|
name,
|
|
email,
|
|
password: hashSync(password),
|
|
emailVerified: verified ? new Date() : undefined,
|
|
url: name,
|
|
},
|
|
});
|
|
};
|
|
|
|
export const unseedUser = async (userId: number) => {
|
|
await prisma.user.delete({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
});
|
|
};
|
|
|
|
export const unseedUserByEmail = async (email: string) => {
|
|
await prisma.user.delete({
|
|
where: {
|
|
email,
|
|
},
|
|
});
|
|
};
|
|
|
|
export const extractUserVerificationToken = async (email: string) => {
|
|
return await prisma.verificationToken.findFirstOrThrow({
|
|
where: {
|
|
identifier: 'confirmation-email',
|
|
user: {
|
|
email,
|
|
},
|
|
},
|
|
});
|
|
};
|