512 lines
12 KiB
TypeScript
512 lines
12 KiB
TypeScript
import {
|
|
Addresses,
|
|
Contacts,
|
|
Customers,
|
|
DeedHasDocumentTypes,
|
|
DeedTypeHasDocumentTypes,
|
|
DeedTypes,
|
|
Deeds,
|
|
DocumentHistory,
|
|
DocumentTypes,
|
|
Documents,
|
|
EDocumentStatus,
|
|
EFolderStatus,
|
|
EOfficeStatus,
|
|
Files,
|
|
OfficeFolderHasCustomers,
|
|
OfficeFolders,
|
|
Offices,
|
|
Users,
|
|
ECivility,
|
|
ECustomerStatus,
|
|
PrismaClient
|
|
} from "@prisma/client";
|
|
|
|
(async () => {
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
const existingData = await prisma.contacts.findFirst({ where: { email: "john.doe@example.com" } });
|
|
if (existingData) {
|
|
console.log('Seed data already exists. Skipping seeding process.');
|
|
return;
|
|
}
|
|
|
|
const randomString = () => {
|
|
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
let result = "";
|
|
for (let i = 10; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
|
|
return result;
|
|
};
|
|
const uidCustomer1: string = randomString();
|
|
const uidCustomer2: string = randomString();
|
|
|
|
const uidContact1: string = randomString();
|
|
const uidContact2: string = randomString();
|
|
|
|
const uidAddress1: string = randomString();
|
|
const uidAddress2: string = randomString();
|
|
|
|
const uidOffice1: string = randomString();
|
|
const uidOffice2: string = randomString();
|
|
|
|
const uidUser1: string = randomString();
|
|
const uidUser2: string = randomString();
|
|
|
|
const uidOfficeFolder1: string = randomString();
|
|
const uidOfficeFolder2: string = randomString();
|
|
const uidOfficeFolder3: string = randomString();
|
|
const uidOfficeFolder4: string = randomString();
|
|
const uidOfficeFolder5: string = randomString();
|
|
|
|
const uidDeed1: string = randomString();
|
|
const uidDeed2: string = randomString();
|
|
const uidDeed3: string = randomString();
|
|
const uidDeed4: string = randomString();
|
|
const uidDeed5: string = randomString();
|
|
|
|
const uidDeedType1: string = randomString();
|
|
const uidDeedType2: string = randomString();
|
|
|
|
const uidDocument1: string = randomString();
|
|
const uidDocument2: string = randomString();
|
|
|
|
const uidDocumentType1: string = randomString();
|
|
const uidDocumentType2: string = randomString();
|
|
|
|
const uidOfficeFolderHasCustomer1: string = randomString();
|
|
const uidOfficeFolderHasCustomer2: string = randomString();
|
|
|
|
const uidFiles1: string = randomString();
|
|
const uidFiles2: string = randomString();
|
|
|
|
const uidDeedHasDocumentType1: string = randomString();
|
|
const uidDeedHasDocumentType2: string = randomString();
|
|
|
|
const uidDeedTypeHasDocumentType1: string = randomString();
|
|
const uidDeedTypeHasDocumentType2: string = randomString();
|
|
|
|
const uidDocumentHistory1: string = randomString();
|
|
const uidDocumentHistory2: string = randomString();
|
|
|
|
const customers: Customers[] = [
|
|
{
|
|
uid: uidCustomer1,
|
|
contact_uid: uidContact1,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
status: ECustomerStatus.PENDING,
|
|
},
|
|
{
|
|
uid: uidCustomer2,
|
|
contact_uid: uidContact2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
status: ECustomerStatus.PENDING,
|
|
},
|
|
];
|
|
|
|
const addresses: Addresses[] = [
|
|
{
|
|
uid: uidAddress1,
|
|
address: "123 Main St",
|
|
city: "Los Angeles",
|
|
zip_code: 90001,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidAddress2,
|
|
address: "Rue Pierre Emillion",
|
|
city: "Paris",
|
|
zip_code: 75003,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
];
|
|
|
|
const contacts: Contacts[] = [
|
|
{
|
|
uid: uidContact1,
|
|
address_uid: uidAddress1,
|
|
first_name: "John",
|
|
last_name: "Doe",
|
|
email: "john.doe@example.com",
|
|
phone_number: randomString(),
|
|
cell_phone_number: randomString(),
|
|
birthdate: null,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
civility: ECivility.MALE,
|
|
},
|
|
{
|
|
uid: uidContact2,
|
|
address_uid: uidAddress2,
|
|
first_name: "Jane",
|
|
last_name: "Doe",
|
|
email: "jane.doe@example.com",
|
|
phone_number: randomString(),
|
|
cell_phone_number: randomString(),
|
|
birthdate: null,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
civility: ECivility.FEMALE,
|
|
},
|
|
];
|
|
|
|
const offices: Offices[] = [
|
|
{
|
|
uid: uidOffice1,
|
|
idNot: randomString(),
|
|
name: "LA Office",
|
|
crpcen: randomString(),
|
|
address_uid: uidAddress1,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
office_status: EOfficeStatus.ACTIVATED,
|
|
},
|
|
{
|
|
uid: uidOffice2,
|
|
idNot: randomString(),
|
|
name: "NYC Office",
|
|
crpcen: randomString(),
|
|
address_uid: uidAddress2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
office_status: EOfficeStatus.DESACTIVATED,
|
|
},
|
|
];
|
|
|
|
const users: Users[] = [
|
|
{
|
|
uid: uidUser1,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
idNot: randomString(),
|
|
contact_uid: uidContact1,
|
|
office_uid: uidOffice1,
|
|
},
|
|
{
|
|
uid: uidUser2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
idNot: randomString(),
|
|
contact_uid: uidContact2,
|
|
office_uid: uidOffice2,
|
|
},
|
|
];
|
|
|
|
const officeFolders: OfficeFolders[] = [
|
|
{
|
|
uid: uidOfficeFolder1,
|
|
folder_number: "0001",
|
|
name: "Dossier",
|
|
deed_uid: uidDeed1,
|
|
status: EFolderStatus.LIVE,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
office_uid: uidOffice1,
|
|
description: null,
|
|
archived_description: null,
|
|
},
|
|
{
|
|
uid: uidOfficeFolder2,
|
|
folder_number: "0002",
|
|
name: "Dossier",
|
|
deed_uid: uidDeed2,
|
|
status: EFolderStatus.LIVE,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
office_uid: uidOffice2,
|
|
description: null,
|
|
archived_description: null,
|
|
},
|
|
{
|
|
uid: uidOfficeFolder3,
|
|
folder_number: "0003",
|
|
name: "Dossier",
|
|
deed_uid: uidDeed3,
|
|
status: EFolderStatus.LIVE,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
office_uid: uidOffice2,
|
|
description: null,
|
|
archived_description: null,
|
|
},
|
|
{
|
|
uid: uidOfficeFolder4,
|
|
folder_number: "0004",
|
|
name: "Dossier",
|
|
deed_uid: uidDeed4,
|
|
status: EFolderStatus.ARCHIVED,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
office_uid: uidOffice2,
|
|
description: null,
|
|
archived_description: null,
|
|
},
|
|
{
|
|
uid: uidOfficeFolder5,
|
|
folder_number: "0005",
|
|
name: "Dossier",
|
|
deed_uid: uidDeed5,
|
|
status: EFolderStatus.ARCHIVED,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
office_uid: uidOffice2,
|
|
description: null,
|
|
archived_description: null,
|
|
}
|
|
];
|
|
|
|
const deeds: Deeds[] = [
|
|
{
|
|
uid: uidDeed1,
|
|
deed_type_uid: uidDeedType1,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidDeed2,
|
|
deed_type_uid: uidDeedType2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidDeed3,
|
|
deed_type_uid: uidDeedType2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidDeed4,
|
|
deed_type_uid: uidDeedType2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidDeed5,
|
|
deed_type_uid: uidDeedType2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
}
|
|
];
|
|
|
|
const deedTypes: DeedTypes[] = [
|
|
{
|
|
uid: uidDeedType1,
|
|
name: "Acte de mariage",
|
|
archived_at: null,
|
|
description: "Acte regroupant deux personnes en mariage",
|
|
office_uid: uidOffice1,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidDeedType2,
|
|
name: "Vente d'un bien immobilier",
|
|
archived_at: null,
|
|
description: "Permet de vendre un bien immobilier à une entité ou une personne physique",
|
|
office_uid: uidOffice2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
];
|
|
|
|
const documents: Documents[] = [
|
|
{
|
|
uid: uidDocument1,
|
|
blockchain_anchor_uid: null,
|
|
depositor_uid: uidCustomer1,
|
|
document_status: EDocumentStatus.ASKED,
|
|
folder_uid: uidOfficeFolder1,
|
|
document_type_uid: uidDocumentType1,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidDocument2,
|
|
blockchain_anchor_uid: null,
|
|
depositor_uid: uidCustomer2,
|
|
document_status: EDocumentStatus.ASKED,
|
|
folder_uid: uidOfficeFolder2,
|
|
document_type_uid: uidDocumentType2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
];
|
|
|
|
const documentTypes: DocumentTypes[] = [
|
|
{
|
|
uid: uidDocumentType1,
|
|
archived_at: null,
|
|
name: "Acte de naissance",
|
|
office_uid: uidOffice1,
|
|
private_description: "Ce document est confidentiel, et ne doit pas être divulgué",
|
|
public_description: "Acte de naissance est un document officiel qui atteste de la naissance d'une personne",
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidDocumentType2,
|
|
archived_at: null,
|
|
name: "Carte d'identité",
|
|
office_uid: uidOffice2,
|
|
private_description: "Ce document est confidentiel, demander un recto-verso au client",
|
|
public_description: "Carte d'identité est un document officiel qui atteste de l'identité d'une personne",
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
];
|
|
|
|
const officeFolderHasCustomers: OfficeFolderHasCustomers[] = [
|
|
{
|
|
uid: uidOfficeFolderHasCustomer1,
|
|
customer_uid: uidCustomer1,
|
|
office_folder_uid: uidOfficeFolder1,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidOfficeFolderHasCustomer2,
|
|
customer_uid: uidCustomer2,
|
|
office_folder_uid: uidOfficeFolder2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
];
|
|
|
|
const files: Files[] = [
|
|
{
|
|
uid: uidFiles1,
|
|
document_uid: uidDocument1,
|
|
file_path: "https://www.google1.com",
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidFiles2,
|
|
document_uid: uidDocument2,
|
|
file_path: "https://www.google2.com",
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
];
|
|
|
|
const deedHasDocumentTypes: DeedHasDocumentTypes[] = [
|
|
{
|
|
uid: uidDeedHasDocumentType1,
|
|
deed_uid: uidDeed1,
|
|
document_type_uid: uidDocumentType1,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidDeedHasDocumentType2,
|
|
deed_uid: uidDeed2,
|
|
document_type_uid: uidDocumentType2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
];
|
|
|
|
const deedTypeHasDocumentTypes: DeedTypeHasDocumentTypes[] = [
|
|
{
|
|
uid: uidDeedTypeHasDocumentType1,
|
|
deed_type_uid: uidDeedType1,
|
|
document_type_uid: uidDocumentType1,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidDeedTypeHasDocumentType2,
|
|
deed_type_uid: uidDeedType2,
|
|
document_type_uid: uidDocumentType2,
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
];
|
|
|
|
const documentHistories: DocumentHistory[] = [
|
|
{
|
|
uid: uidDocumentHistory1,
|
|
document_status: EDocumentStatus.ASKED,
|
|
document_uid: uidDocument1,
|
|
refused_reason: "Le document n'est pas conforme",
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
{
|
|
uid: uidDocumentHistory2,
|
|
document_status: EDocumentStatus.DEPOSITED,
|
|
document_uid: uidDocument1,
|
|
refused_reason: "Le document n'est pas conforme",
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
},
|
|
];
|
|
|
|
|
|
for (const address of addresses) {
|
|
await prisma.addresses.create({data: address});
|
|
}
|
|
|
|
for (const contact of contacts) {
|
|
await prisma.contacts.create({ data: contact });
|
|
}
|
|
|
|
for (const office of offices) {
|
|
await prisma.offices.create({ data: office });
|
|
}
|
|
|
|
for (const user of users) {
|
|
await prisma.users.create({ data: user });
|
|
}
|
|
|
|
|
|
for (const customer of customers) {
|
|
await prisma.customers.create({ data: customer });
|
|
}
|
|
|
|
for (const deedType of deedTypes) {
|
|
await prisma.deedTypes.create({ data: deedType });
|
|
}
|
|
|
|
for (const deed of deeds) {
|
|
await prisma.deeds.create({ data: deed });
|
|
|
|
}
|
|
for (const officeFolder of officeFolders) {
|
|
await prisma.officeFolders.create({ data: officeFolder });
|
|
}
|
|
|
|
for (const documentType of documentTypes) {
|
|
await prisma.documentTypes.create({ data: documentType });
|
|
}
|
|
|
|
for (const document of documents) {
|
|
await prisma.documents.create({ data: document });
|
|
}
|
|
|
|
for (const file of files) {
|
|
await prisma.files.create({ data: file });
|
|
}
|
|
|
|
for (const documentHistory of documentHistories) {
|
|
await prisma.documentHistory.create({ data: documentHistory });
|
|
}
|
|
|
|
for (const officeFolderHasCustomer of officeFolderHasCustomers) {
|
|
await prisma.officeFolderHasCustomers.create({ data: officeFolderHasCustomer });
|
|
}
|
|
|
|
for (const deedHasDocumentType of deedHasDocumentTypes) {
|
|
await prisma.deedHasDocumentTypes.create({ data: deedHasDocumentType });
|
|
}
|
|
|
|
for (const deedTypeHasDocumentType of deedTypeHasDocumentTypes) {
|
|
await prisma.deedTypeHasDocumentTypes.create({ data: deedTypeHasDocumentType });
|
|
}
|
|
|
|
console.log(">MOCK DATA - Seeding completed!");
|
|
})(); |