33738/backend/src/db/seeders/20231127130745-sample-data.js
2025-08-30 02:54:41 +00:00

843 lines
18 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Cases = db.cases;
const Documents = db.documents;
const Events = db.events;
const MedicalRecords = db.medical_records;
const Settlements = db.settlements;
const Tasks = db.tasks;
const Firms = db.firms;
const CasesData = [
{
title: 'Smith vs. Insurance Co.',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'Johnson vs. Auto Corp.',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'Doe vs. Health Services',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
title: 'Brown vs. State',
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const DocumentsData = [
{
name: 'Demand Letter',
// type code here for "files" field
// type code here for "relation_one" field
},
{
name: 'Settlement Agreement',
// type code here for "files" field
// type code here for "relation_one" field
},
{
name: 'Medical Records',
// type code here for "files" field
// type code here for "relation_one" field
},
{
name: 'Pleadings',
// type code here for "files" field
// type code here for "relation_one" field
},
];
const EventsData = [
{
name: 'Mediation Session',
start_date: new Date('2023-11-18T09:00:00Z'),
end_date: new Date('2023-11-18T11:00:00Z'),
// type code here for "relation_one" field
},
{
name: 'Court Hearing',
start_date: new Date('2023-11-22T13:00:00Z'),
end_date: new Date('2023-11-22T15:00:00Z'),
// type code here for "relation_one" field
},
{
name: 'Client Meeting',
start_date: new Date('2023-11-27T10:00:00Z'),
end_date: new Date('2023-11-27T11:00:00Z'),
// type code here for "relation_one" field
},
{
name: 'Settlement Conference',
start_date: new Date('2023-12-01T14:00:00Z'),
end_date: new Date('2023-12-01T16:00:00Z'),
// type code here for "relation_one" field
},
];
const MedicalRecordsData = [
{
provider: 'City Hospital',
received_date: new Date('2023-11-10T00:00:00Z'),
// type code here for "relation_one" field
},
{
provider: 'Health Clinic',
received_date: new Date('2023-11-12T00:00:00Z'),
// type code here for "relation_one" field
},
{
provider: 'General Hospital',
received_date: new Date('2023-11-14T00:00:00Z'),
// type code here for "relation_one" field
},
{
provider: 'Specialty Clinic',
received_date: new Date('2023-11-16T00:00:00Z'),
// type code here for "relation_one" field
},
];
const SettlementsData = [
{
description: 'Initial settlement offer',
amount: 50000,
// type code here for "relation_one" field
},
{
description: 'Final settlement agreement',
amount: 75000,
// type code here for "relation_one" field
},
{
description: 'Proposed settlement terms',
amount: 30000,
// type code here for "relation_one" field
},
{
description: 'Settlement negotiation',
amount: 100000,
// type code here for "relation_one" field
},
];
const TasksData = [
{
description: 'Review medical records',
due_date: new Date('2023-11-15T10:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Prepare settlement offer',
due_date: new Date('2023-11-20T10:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'Draft pleadings',
due_date: new Date('2023-11-25T10:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
{
description: 'File court documents',
due_date: new Date('2023-11-30T10:00:00Z'),
// type code here for "relation_one" field
// type code here for "relation_one" field
},
];
const FirmsData = [
{
name: 'Legal Eagles LLP',
},
{
name: 'Injury Advocates',
},
{
name: 'Family Law Group',
},
{
name: 'Corporate Counselors',
},
];
// Similar logic for "relation_many"
async function associateUserWithFirm() {
const relatedFirm0 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setFirm) {
await User0.setFirm(relatedFirm0);
}
const relatedFirm1 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setFirm) {
await User1.setFirm(relatedFirm1);
}
const relatedFirm2 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setFirm) {
await User2.setFirm(relatedFirm2);
}
const relatedFirm3 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const User3 = await Users.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (User3?.setFirm) {
await User3.setFirm(relatedFirm3);
}
}
async function associateCaseWithFirm() {
const relatedFirm0 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Case0 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Case0?.setFirm) {
await Case0.setFirm(relatedFirm0);
}
const relatedFirm1 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Case1 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Case1?.setFirm) {
await Case1.setFirm(relatedFirm1);
}
const relatedFirm2 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Case2 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Case2?.setFirm) {
await Case2.setFirm(relatedFirm2);
}
const relatedFirm3 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Case3 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Case3?.setFirm) {
await Case3.setFirm(relatedFirm3);
}
}
async function associateCaseWithAttorney() {
const relatedAttorney0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Case0 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Case0?.setAttorney) {
await Case0.setAttorney(relatedAttorney0);
}
const relatedAttorney1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Case1 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Case1?.setAttorney) {
await Case1.setAttorney(relatedAttorney1);
}
const relatedAttorney2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Case2 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Case2?.setAttorney) {
await Case2.setAttorney(relatedAttorney2);
}
const relatedAttorney3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Case3 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Case3?.setAttorney) {
await Case3.setAttorney(relatedAttorney3);
}
}
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
async function associateCaseWithFirm() {
const relatedFirm0 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Case0 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Case0?.setFirm) {
await Case0.setFirm(relatedFirm0);
}
const relatedFirm1 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Case1 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Case1?.setFirm) {
await Case1.setFirm(relatedFirm1);
}
const relatedFirm2 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Case2 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Case2?.setFirm) {
await Case2.setFirm(relatedFirm2);
}
const relatedFirm3 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Case3 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Case3?.setFirm) {
await Case3.setFirm(relatedFirm3);
}
}
async function associateDocumentWithFirm() {
const relatedFirm0 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Document0 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Document0?.setFirm) {
await Document0.setFirm(relatedFirm0);
}
const relatedFirm1 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Document1 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Document1?.setFirm) {
await Document1.setFirm(relatedFirm1);
}
const relatedFirm2 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Document2 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Document2?.setFirm) {
await Document2.setFirm(relatedFirm2);
}
const relatedFirm3 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Document3 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Document3?.setFirm) {
await Document3.setFirm(relatedFirm3);
}
}
async function associateEventWithFirm() {
const relatedFirm0 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Event0 = await Events.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Event0?.setFirm) {
await Event0.setFirm(relatedFirm0);
}
const relatedFirm1 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Event1 = await Events.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Event1?.setFirm) {
await Event1.setFirm(relatedFirm1);
}
const relatedFirm2 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Event2 = await Events.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Event2?.setFirm) {
await Event2.setFirm(relatedFirm2);
}
const relatedFirm3 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Event3 = await Events.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Event3?.setFirm) {
await Event3.setFirm(relatedFirm3);
}
}
async function associateMedicalRecordWithFirm() {
const relatedFirm0 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const MedicalRecord0 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (MedicalRecord0?.setFirm) {
await MedicalRecord0.setFirm(relatedFirm0);
}
const relatedFirm1 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const MedicalRecord1 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (MedicalRecord1?.setFirm) {
await MedicalRecord1.setFirm(relatedFirm1);
}
const relatedFirm2 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const MedicalRecord2 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (MedicalRecord2?.setFirm) {
await MedicalRecord2.setFirm(relatedFirm2);
}
const relatedFirm3 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const MedicalRecord3 = await MedicalRecords.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (MedicalRecord3?.setFirm) {
await MedicalRecord3.setFirm(relatedFirm3);
}
}
async function associateSettlementWithFirm() {
const relatedFirm0 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Settlement0 = await Settlements.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Settlement0?.setFirm) {
await Settlement0.setFirm(relatedFirm0);
}
const relatedFirm1 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Settlement1 = await Settlements.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Settlement1?.setFirm) {
await Settlement1.setFirm(relatedFirm1);
}
const relatedFirm2 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Settlement2 = await Settlements.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Settlement2?.setFirm) {
await Settlement2.setFirm(relatedFirm2);
}
const relatedFirm3 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Settlement3 = await Settlements.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Settlement3?.setFirm) {
await Settlement3.setFirm(relatedFirm3);
}
}
async function associateTaskWithAssigned_to() {
const relatedAssigned_to0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task0 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Task0?.setAssigned_to) {
await Task0.setAssigned_to(relatedAssigned_to0);
}
const relatedAssigned_to1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task1 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Task1?.setAssigned_to) {
await Task1.setAssigned_to(relatedAssigned_to1);
}
const relatedAssigned_to2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task2 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Task2?.setAssigned_to) {
await Task2.setAssigned_to(relatedAssigned_to2);
}
const relatedAssigned_to3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Task3 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Task3?.setAssigned_to) {
await Task3.setAssigned_to(relatedAssigned_to3);
}
}
async function associateTaskWithFirm() {
const relatedFirm0 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Task0 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Task0?.setFirm) {
await Task0.setFirm(relatedFirm0);
}
const relatedFirm1 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Task1 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Task1?.setFirm) {
await Task1.setFirm(relatedFirm1);
}
const relatedFirm2 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Task2 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Task2?.setFirm) {
await Task2.setFirm(relatedFirm2);
}
const relatedFirm3 = await Firms.findOne({
offset: Math.floor(Math.random() * (await Firms.count())),
});
const Task3 = await Tasks.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Task3?.setFirm) {
await Task3.setFirm(relatedFirm3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Cases.bulkCreate(CasesData);
await Documents.bulkCreate(DocumentsData);
await Events.bulkCreate(EventsData);
await MedicalRecords.bulkCreate(MedicalRecordsData);
await Settlements.bulkCreate(SettlementsData);
await Tasks.bulkCreate(TasksData);
await Firms.bulkCreate(FirmsData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithFirm(),
await associateCaseWithFirm(),
await associateCaseWithAttorney(),
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
// Similar logic for "relation_many"
await associateCaseWithFirm(),
await associateDocumentWithFirm(),
await associateEventWithFirm(),
await associateMedicalRecordWithFirm(),
await associateSettlementWithFirm(),
await associateTaskWithAssigned_to(),
await associateTaskWithFirm(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('cases', null, {});
await queryInterface.bulkDelete('documents', null, {});
await queryInterface.bulkDelete('events', null, {});
await queryInterface.bulkDelete('medical_records', null, {});
await queryInterface.bulkDelete('settlements', null, {});
await queryInterface.bulkDelete('tasks', null, {});
await queryInterface.bulkDelete('firms', null, {});
},
};