mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 16:51:38 +10:00
chore: update local seed data (#1622)
Add multiple example documents, pending documents, and templates for both admin and example users
This commit is contained in:
committed by
David Nguyen
parent
b205f7e5f3
commit
87dcdd44cd
2
package-lock.json
generated
2
package-lock.json
generated
@ -42439,4 +42439,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5,6 +5,18 @@ import { hashSync } from '@documenso/lib/server-only/auth/hash';
|
|||||||
|
|
||||||
import { prisma } from '..';
|
import { prisma } from '..';
|
||||||
import { DocumentDataType, DocumentSource, Role, TeamMemberRole } from '../client';
|
import { DocumentDataType, DocumentSource, Role, TeamMemberRole } from '../client';
|
||||||
|
import { seedPendingDocument } from './documents';
|
||||||
|
import { seedDirectTemplate, seedTemplate } from './templates';
|
||||||
|
|
||||||
|
const createDocumentData = async ({ documentData }: { documentData: string }) => {
|
||||||
|
return prisma.documentData.create({
|
||||||
|
data: {
|
||||||
|
type: DocumentDataType.BYTES_64,
|
||||||
|
data: documentData,
|
||||||
|
initialData: documentData,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const seedDatabase = async () => {
|
export const seedDatabase = async () => {
|
||||||
const examplePdf = fs
|
const examplePdf = fs
|
||||||
@ -39,35 +51,80 @@ export const seedDatabase = async () => {
|
|||||||
update: {},
|
update: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
const examplePdfData = await prisma.documentData.upsert({
|
for (let i = 1; i <= 4; i++) {
|
||||||
where: {
|
const documentData = await createDocumentData({ documentData: examplePdf });
|
||||||
id: 'clmn0kv5k0000pe04vcqg5zla',
|
|
||||||
},
|
|
||||||
create: {
|
|
||||||
id: 'clmn0kv5k0000pe04vcqg5zla',
|
|
||||||
type: DocumentDataType.BYTES_64,
|
|
||||||
data: examplePdf,
|
|
||||||
initialData: examplePdf,
|
|
||||||
},
|
|
||||||
update: {},
|
|
||||||
});
|
|
||||||
|
|
||||||
await prisma.document.create({
|
await prisma.document.create({
|
||||||
data: {
|
data: {
|
||||||
source: DocumentSource.DOCUMENT,
|
source: DocumentSource.DOCUMENT,
|
||||||
title: 'Example Document',
|
title: `Example Document ${i}`,
|
||||||
documentDataId: examplePdfData.id,
|
documentDataId: documentData.id,
|
||||||
userId: exampleUser.id,
|
userId: exampleUser.id,
|
||||||
recipients: {
|
recipients: {
|
||||||
create: {
|
create: {
|
||||||
name: String(adminUser.name),
|
name: String(adminUser.name),
|
||||||
email: adminUser.email,
|
email: adminUser.email,
|
||||||
token: Math.random().toString(36).slice(2, 9),
|
token: Math.random().toString(36).slice(2, 9),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 1; i <= 4; i++) {
|
||||||
|
const documentData = await createDocumentData({ documentData: examplePdf });
|
||||||
|
|
||||||
|
await prisma.document.create({
|
||||||
|
data: {
|
||||||
|
source: DocumentSource.DOCUMENT,
|
||||||
|
title: `Document ${i}`,
|
||||||
|
documentDataId: documentData.id,
|
||||||
|
userId: adminUser.id,
|
||||||
|
recipients: {
|
||||||
|
create: {
|
||||||
|
name: String(exampleUser.name),
|
||||||
|
email: exampleUser.email,
|
||||||
|
token: Math.random().toString(36).slice(2, 9),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await seedPendingDocument(exampleUser, [adminUser], {
|
||||||
|
key: 'example-pending',
|
||||||
|
createDocumentOptions: {
|
||||||
|
title: 'Pending Document',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await seedPendingDocument(adminUser, [exampleUser], {
|
||||||
|
key: 'admin-pending',
|
||||||
|
createDocumentOptions: {
|
||||||
|
title: 'Pending Document',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
seedTemplate({
|
||||||
|
title: 'Template 1',
|
||||||
|
userId: exampleUser.id,
|
||||||
|
}),
|
||||||
|
seedDirectTemplate({
|
||||||
|
title: 'Direct Template 1',
|
||||||
|
userId: exampleUser.id,
|
||||||
|
}),
|
||||||
|
|
||||||
|
seedTemplate({
|
||||||
|
title: 'Template 1',
|
||||||
|
userId: adminUser.id,
|
||||||
|
}),
|
||||||
|
seedDirectTemplate({
|
||||||
|
title: 'Direct Template 1',
|
||||||
|
userId: adminUser.id,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
const testUsers = [
|
const testUsers = [
|
||||||
'test@documenso.com',
|
'test@documenso.com',
|
||||||
'test2@documenso.com',
|
'test2@documenso.com',
|
||||||
|
|||||||
Reference in New Issue
Block a user