32911/backend/src/db/seeders/20231127130745-sample-data.js
2025-07-19 00:27:23 +00:00

615 lines
14 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Cases = db.cases;
const Clients = db.clients;
const Documents = db.documents;
const Despachos = db.despachos;
const CasesData = [
{
title: 'Smith vs. Johnson',
// type code here for "relation_one" field
// type code here for "relation_one" field
start_date: new Date('2023-01-15T09:00:00Z'),
end_date: new Date('2023-02-15T17:00:00Z'),
status: 'InProgress',
// type code here for "relation_one" field
},
{
title: 'Doe vs. Corporation',
// type code here for "relation_one" field
// type code here for "relation_one" field
start_date: new Date('2023-03-01T09:00:00Z'),
end_date: new Date('2023-04-01T17:00:00Z'),
status: 'InProgress',
// type code here for "relation_one" field
},
{
title: 'White vs. State',
// type code here for "relation_one" field
// type code here for "relation_one" field
start_date: new Date('2023-05-10T09:00:00Z'),
end_date: new Date('2023-06-10T17:00:00Z'),
status: 'Closed',
// type code here for "relation_one" field
},
{
title: 'Johnson vs. Enterprise',
// type code here for "relation_one" field
// type code here for "relation_one" field
start_date: new Date('2023-07-20T09:00:00Z'),
end_date: new Date('2023-08-20T17:00:00Z'),
status: 'Open',
// type code here for "relation_one" field
},
{
title: 'Lee vs. Municipality',
// type code here for "relation_one" field
// type code here for "relation_one" field
start_date: new Date('2023-09-05T09:00:00Z'),
end_date: new Date('2023-10-05T17:00:00Z'),
status: 'Closed',
// type code here for "relation_one" field
},
];
const ClientsData = [
{
first_name: 'John',
last_name: 'Doe',
email: 'john.doe@clientmail.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Anna',
last_name: 'Smith',
email: 'anna.smith@clientmail.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Brian',
last_name: 'White',
email: 'brian.white@clientmail.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'Catherine',
last_name: 'Johnson',
email: 'catherine.johnson@clientmail.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
first_name: 'David',
last_name: 'Lee',
email: 'david.lee@clientmail.com',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
const DocumentsData = [
{
title: 'Contract Draft',
// type code here for "files" field
uploaded_at: new Date('2023-01-16T10:00:00Z'),
// type code here for "relation_one" field
},
{
title: 'Evidence Photos',
// type code here for "files" field
uploaded_at: new Date('2023-03-02T11:00:00Z'),
// type code here for "relation_one" field
},
{
title: 'Court Summons',
// type code here for "files" field
uploaded_at: new Date('2023-05-11T12:00:00Z'),
// type code here for "relation_one" field
},
{
title: 'Witness Statement',
// type code here for "files" field
uploaded_at: new Date('2023-07-21T13:00:00Z'),
// type code here for "relation_one" field
},
{
title: 'Legal Brief',
// type code here for "files" field
uploaded_at: new Date('2023-09-06T14:00:00Z'),
// type code here for "relation_one" field
},
];
const DespachosData = [
{
name: 'Legal Eagles',
},
{
name: 'Justice League',
},
{
name: 'Law & Order',
},
{
name: 'Court Masters',
},
{
name: 'Advocate Group',
},
];
// Similar logic for "relation_many"
async function associateUserWithDespacho() {
const relatedDespacho0 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const User0 = await Users.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (User0?.setDespacho) {
await User0.setDespacho(relatedDespacho0);
}
const relatedDespacho1 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const User1 = await Users.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (User1?.setDespacho) {
await User1.setDespacho(relatedDespacho1);
}
const relatedDespacho2 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const User2 = await Users.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (User2?.setDespacho) {
await User2.setDespacho(relatedDespacho2);
}
const relatedDespacho3 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const User3 = await Users.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (User3?.setDespacho) {
await User3.setDespacho(relatedDespacho3);
}
const relatedDespacho4 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const User4 = await Users.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (User4?.setDespacho) {
await User4.setDespacho(relatedDespacho4);
}
}
async function associateCaseWithDespacho() {
const relatedDespacho0 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Case0 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Case0?.setDespacho) {
await Case0.setDespacho(relatedDespacho0);
}
const relatedDespacho1 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Case1 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Case1?.setDespacho) {
await Case1.setDespacho(relatedDespacho1);
}
const relatedDespacho2 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Case2 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Case2?.setDespacho) {
await Case2.setDespacho(relatedDespacho2);
}
const relatedDespacho3 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Case3 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Case3?.setDespacho) {
await Case3.setDespacho(relatedDespacho3);
}
const relatedDespacho4 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Case4 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Case4?.setDespacho) {
await Case4.setDespacho(relatedDespacho4);
}
}
async function associateCaseWithAssigned_lawyer() {
const relatedAssigned_lawyer0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Case0 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Case0?.setAssigned_lawyer) {
await Case0.setAssigned_lawyer(relatedAssigned_lawyer0);
}
const relatedAssigned_lawyer1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Case1 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Case1?.setAssigned_lawyer) {
await Case1.setAssigned_lawyer(relatedAssigned_lawyer1);
}
const relatedAssigned_lawyer2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Case2 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Case2?.setAssigned_lawyer) {
await Case2.setAssigned_lawyer(relatedAssigned_lawyer2);
}
const relatedAssigned_lawyer3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Case3 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Case3?.setAssigned_lawyer) {
await Case3.setAssigned_lawyer(relatedAssigned_lawyer3);
}
const relatedAssigned_lawyer4 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Case4 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Case4?.setAssigned_lawyer) {
await Case4.setAssigned_lawyer(relatedAssigned_lawyer4);
}
}
async function associateCaseWithDespacho() {
const relatedDespacho0 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Case0 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Case0?.setDespacho) {
await Case0.setDespacho(relatedDespacho0);
}
const relatedDespacho1 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Case1 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Case1?.setDespacho) {
await Case1.setDespacho(relatedDespacho1);
}
const relatedDespacho2 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Case2 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Case2?.setDespacho) {
await Case2.setDespacho(relatedDespacho2);
}
const relatedDespacho3 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Case3 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Case3?.setDespacho) {
await Case3.setDespacho(relatedDespacho3);
}
const relatedDespacho4 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Case4 = await Cases.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Case4?.setDespacho) {
await Case4.setDespacho(relatedDespacho4);
}
}
// Similar logic for "relation_many"
async function associateClientWithDespacho() {
const relatedDespacho0 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Client0 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Client0?.setDespacho) {
await Client0.setDespacho(relatedDespacho0);
}
const relatedDespacho1 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Client1 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Client1?.setDespacho) {
await Client1.setDespacho(relatedDespacho1);
}
const relatedDespacho2 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Client2 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Client2?.setDespacho) {
await Client2.setDespacho(relatedDespacho2);
}
const relatedDespacho3 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Client3 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Client3?.setDespacho) {
await Client3.setDespacho(relatedDespacho3);
}
const relatedDespacho4 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Client4 = await Clients.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Client4?.setDespacho) {
await Client4.setDespacho(relatedDespacho4);
}
}
async function associateDocumentWithDespacho() {
const relatedDespacho0 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Document0 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Document0?.setDespacho) {
await Document0.setDespacho(relatedDespacho0);
}
const relatedDespacho1 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Document1 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Document1?.setDespacho) {
await Document1.setDespacho(relatedDespacho1);
}
const relatedDespacho2 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Document2 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Document2?.setDespacho) {
await Document2.setDespacho(relatedDespacho2);
}
const relatedDespacho3 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Document3 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Document3?.setDespacho) {
await Document3.setDespacho(relatedDespacho3);
}
const relatedDespacho4 = await Despachos.findOne({
offset: Math.floor(Math.random() * (await Despachos.count())),
});
const Document4 = await Documents.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Document4?.setDespacho) {
await Document4.setDespacho(relatedDespacho4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Cases.bulkCreate(CasesData);
await Clients.bulkCreate(ClientsData);
await Documents.bulkCreate(DocumentsData);
await Despachos.bulkCreate(DespachosData);
await Promise.all([
// Similar logic for "relation_many"
await associateUserWithDespacho(),
await associateCaseWithDespacho(),
await associateCaseWithAssigned_lawyer(),
await associateCaseWithDespacho(),
// Similar logic for "relation_many"
await associateClientWithDespacho(),
await associateDocumentWithDespacho(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('cases', null, {});
await queryInterface.bulkDelete('clients', null, {});
await queryInterface.bulkDelete('documents', null, {});
await queryInterface.bulkDelete('despachos', null, {});
},
};