1083 lines
24 KiB
JavaScript
1083 lines
24 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Customers = db.customers;
|
|
|
|
const Projects = db.projects;
|
|
|
|
const Tasks = db.tasks;
|
|
|
|
const Timesheets = db.timesheets;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const CustomersData = [
|
|
{
|
|
name: 'Acme Corp',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
PhoneNumber: 'Francis Galton',
|
|
|
|
InvoicingEmail: 'Hans Bethe',
|
|
|
|
Address: 'John Dalton',
|
|
},
|
|
|
|
{
|
|
name: 'Globex Inc',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
PhoneNumber: 'Carl Linnaeus',
|
|
|
|
InvoicingEmail: 'Euclid',
|
|
|
|
Address: 'Hermann von Helmholtz',
|
|
},
|
|
|
|
{
|
|
name: 'Initech',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
PhoneNumber: 'Jonas Salk',
|
|
|
|
InvoicingEmail: 'Gertrude Belle Elion',
|
|
|
|
Address: 'Franz Boas',
|
|
},
|
|
|
|
{
|
|
name: 'Umbrella Corp',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
PhoneNumber: 'Erwin Schrodinger',
|
|
|
|
InvoicingEmail: 'Max Delbruck',
|
|
|
|
Address: 'Karl Landsteiner',
|
|
},
|
|
|
|
{
|
|
name: 'Hooli',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
PhoneNumber: 'Ludwig Boltzmann',
|
|
|
|
InvoicingEmail: 'Anton van Leeuwenhoek',
|
|
|
|
Address: 'Edward Teller',
|
|
},
|
|
];
|
|
|
|
const ProjectsData = [
|
|
{
|
|
name: 'Project Alpha',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
budget: 50000,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
DevelopmentCost: 28.78,
|
|
|
|
MaintenanceCost: 84.45,
|
|
|
|
ExpenseCost: 'Comte de Buffon',
|
|
|
|
Profits: 28.31,
|
|
|
|
StartDate: new Date(Date.now()),
|
|
|
|
EndDate: 'Lynn Margulis',
|
|
},
|
|
|
|
{
|
|
name: 'Project Beta',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
budget: 75000,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
DevelopmentCost: 30.77,
|
|
|
|
MaintenanceCost: 86.18,
|
|
|
|
ExpenseCost: 'Marie Curie',
|
|
|
|
Profits: 62.16,
|
|
|
|
StartDate: new Date(Date.now()),
|
|
|
|
EndDate: 'Pierre Simon de Laplace',
|
|
},
|
|
|
|
{
|
|
name: 'Project Gamma',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
budget: 100000,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
DevelopmentCost: 64.96,
|
|
|
|
MaintenanceCost: 79.67,
|
|
|
|
ExpenseCost: 'Max Planck',
|
|
|
|
Profits: 56.37,
|
|
|
|
StartDate: new Date(Date.now()),
|
|
|
|
EndDate: 'Lucretius',
|
|
},
|
|
|
|
{
|
|
name: 'Project Delta',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
budget: 150000,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
DevelopmentCost: 90.49,
|
|
|
|
MaintenanceCost: 32.89,
|
|
|
|
ExpenseCost: 'James Watson',
|
|
|
|
Profits: 20.72,
|
|
|
|
StartDate: new Date(Date.now()),
|
|
|
|
EndDate: 'Edwin Hubble',
|
|
},
|
|
|
|
{
|
|
name: 'Project Epsilon',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
budget: 200000,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
DevelopmentCost: 78.95,
|
|
|
|
MaintenanceCost: 88.86,
|
|
|
|
ExpenseCost: 'Ernst Haeckel',
|
|
|
|
Profits: 66.52,
|
|
|
|
StartDate: new Date(Date.now()),
|
|
|
|
EndDate: 'Charles Darwin',
|
|
},
|
|
];
|
|
|
|
const TasksData = [
|
|
{
|
|
title: 'Design Phase',
|
|
|
|
status: 'Completed',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-11-01T09:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-15T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
TaskType: 'User Story',
|
|
|
|
EpicEstimatedCost: 69.74,
|
|
|
|
EpicActualCost: 15.68,
|
|
|
|
EpicEstimatedTime: 2,
|
|
|
|
EpicCostVariance: 48.99,
|
|
|
|
EpicActualTime: 7,
|
|
|
|
EpicVarianceTime: 7,
|
|
|
|
EpicCompletionRate: 'Joseph J. Thomson',
|
|
},
|
|
|
|
{
|
|
title: 'Development Phase',
|
|
|
|
status: 'Completed',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-11-16T09:00:00Z'),
|
|
|
|
end_date: new Date('2023-12-15T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
TaskType: 'User Story',
|
|
|
|
EpicEstimatedCost: 72.24,
|
|
|
|
EpicActualCost: 31.96,
|
|
|
|
EpicEstimatedTime: 5,
|
|
|
|
EpicCostVariance: 31.11,
|
|
|
|
EpicActualTime: 9,
|
|
|
|
EpicVarianceTime: 7,
|
|
|
|
EpicCompletionRate: 'Wilhelm Wundt',
|
|
},
|
|
|
|
{
|
|
title: 'Testing Phase',
|
|
|
|
status: 'Completed',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-12-16T09:00:00Z'),
|
|
|
|
end_date: new Date('2023-12-31T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
TaskType: 'User Story',
|
|
|
|
EpicEstimatedCost: 52.63,
|
|
|
|
EpicActualCost: 70.55,
|
|
|
|
EpicEstimatedTime: 7,
|
|
|
|
EpicCostVariance: 11.14,
|
|
|
|
EpicActualTime: 7,
|
|
|
|
EpicVarianceTime: 5,
|
|
|
|
EpicCompletionRate: 'Johannes Kepler',
|
|
},
|
|
|
|
{
|
|
title: 'Deployment Phase',
|
|
|
|
status: 'Completed',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2024-01-01T09:00:00Z'),
|
|
|
|
end_date: new Date('2024-01-15T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
TaskType: 'Epic',
|
|
|
|
EpicEstimatedCost: 76.17,
|
|
|
|
EpicActualCost: 17.91,
|
|
|
|
EpicEstimatedTime: 5,
|
|
|
|
EpicCostVariance: 78.78,
|
|
|
|
EpicActualTime: 6,
|
|
|
|
EpicVarianceTime: 9,
|
|
|
|
EpicCompletionRate: 'John Bardeen',
|
|
},
|
|
|
|
{
|
|
title: 'Requirement Gathering',
|
|
|
|
status: 'Completed',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
end_date: new Date('2023-10-15T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
TaskType: 'Epic',
|
|
|
|
EpicEstimatedCost: 62.61,
|
|
|
|
EpicActualCost: 79.85,
|
|
|
|
EpicEstimatedTime: 3,
|
|
|
|
EpicCostVariance: 33.23,
|
|
|
|
EpicActualTime: 1,
|
|
|
|
EpicVarianceTime: 8,
|
|
|
|
EpicCompletionRate: 'Alfred Kinsey',
|
|
},
|
|
];
|
|
|
|
const TimesheetsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
hours: 8,
|
|
|
|
date: new Date('2023-11-01T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
hours: 6,
|
|
|
|
date: new Date('2023-11-02T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
hours: 7,
|
|
|
|
date: new Date('2023-11-03T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
hours: 5,
|
|
|
|
date: new Date('2023-11-04T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
hours: 9,
|
|
|
|
date: new Date('2023-11-05T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'Tech Innovators',
|
|
},
|
|
|
|
{
|
|
name: 'Green Solutions',
|
|
},
|
|
|
|
{
|
|
name: 'Blue Sky Enterprises',
|
|
},
|
|
|
|
{
|
|
name: 'Future Tech',
|
|
},
|
|
|
|
{
|
|
name: 'Creative Minds',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setOrganization) {
|
|
await User0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setOrganization) {
|
|
await User1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setOrganization) {
|
|
await User2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setOrganization) {
|
|
await User3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User4 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (User4?.setOrganization) {
|
|
await User4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateCustomerWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer0 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Customer0?.setOrganization) {
|
|
await Customer0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer1 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Customer1?.setOrganization) {
|
|
await Customer1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer2 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Customer2?.setOrganization) {
|
|
await Customer2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer3 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Customer3?.setOrganization) {
|
|
await Customer3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Customer4 = await Customers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Customer4?.setOrganization) {
|
|
await Customer4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateProjectWithCustomer() {
|
|
const relatedCustomer0 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Project0 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Project0?.setCustomer) {
|
|
await Project0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Project1 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Project1?.setCustomer) {
|
|
await Project1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Project2 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Project2?.setCustomer) {
|
|
await Project2.setCustomer(relatedCustomer2);
|
|
}
|
|
|
|
const relatedCustomer3 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Project3 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Project3?.setCustomer) {
|
|
await Project3.setCustomer(relatedCustomer3);
|
|
}
|
|
|
|
const relatedCustomer4 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Project4 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Project4?.setCustomer) {
|
|
await Project4.setCustomer(relatedCustomer4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateProjectWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Project0 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Project0?.setOrganization) {
|
|
await Project0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Project1 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Project1?.setOrganization) {
|
|
await Project1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Project2 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Project2?.setOrganization) {
|
|
await Project2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Project3 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Project3?.setOrganization) {
|
|
await Project3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Project4 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Project4?.setOrganization) {
|
|
await Project4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateProjectWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Project0 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Project0?.setOrganization) {
|
|
await Project0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Project1 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Project1?.setOrganization) {
|
|
await Project1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Project2 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Project2?.setOrganization) {
|
|
await Project2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Project3 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Project3?.setOrganization) {
|
|
await Project3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Project4 = await Projects.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Project4?.setOrganization) {
|
|
await Project4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateTaskWithProject() {
|
|
const relatedProject0 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Task0 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Task0?.setProject) {
|
|
await Task0.setProject(relatedProject0);
|
|
}
|
|
|
|
const relatedProject1 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Task1 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Task1?.setProject) {
|
|
await Task1.setProject(relatedProject1);
|
|
}
|
|
|
|
const relatedProject2 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Task2 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Task2?.setProject) {
|
|
await Task2.setProject(relatedProject2);
|
|
}
|
|
|
|
const relatedProject3 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Task3 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Task3?.setProject) {
|
|
await Task3.setProject(relatedProject3);
|
|
}
|
|
|
|
const relatedProject4 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Task4 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Task4?.setProject) {
|
|
await Task4.setProject(relatedProject4);
|
|
}
|
|
}
|
|
|
|
async function associateTaskWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Task0 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Task0?.setOrganization) {
|
|
await Task0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Task1 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Task1?.setOrganization) {
|
|
await Task1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Task2 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Task2?.setOrganization) {
|
|
await Task2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Task3 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Task3?.setOrganization) {
|
|
await Task3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Task4 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Task4?.setOrganization) {
|
|
await Task4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateTimesheetWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Timesheet0 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Timesheet0?.setUser) {
|
|
await Timesheet0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Timesheet1 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Timesheet1?.setUser) {
|
|
await Timesheet1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Timesheet2 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Timesheet2?.setUser) {
|
|
await Timesheet2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Timesheet3 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Timesheet3?.setUser) {
|
|
await Timesheet3.setUser(relatedUser3);
|
|
}
|
|
|
|
const relatedUser4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Timesheet4 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Timesheet4?.setUser) {
|
|
await Timesheet4.setUser(relatedUser4);
|
|
}
|
|
}
|
|
|
|
async function associateTimesheetWithTask() {
|
|
const relatedTask0 = await Tasks.findOne({
|
|
offset: Math.floor(Math.random() * (await Tasks.count())),
|
|
});
|
|
const Timesheet0 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Timesheet0?.setTask) {
|
|
await Timesheet0.setTask(relatedTask0);
|
|
}
|
|
|
|
const relatedTask1 = await Tasks.findOne({
|
|
offset: Math.floor(Math.random() * (await Tasks.count())),
|
|
});
|
|
const Timesheet1 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Timesheet1?.setTask) {
|
|
await Timesheet1.setTask(relatedTask1);
|
|
}
|
|
|
|
const relatedTask2 = await Tasks.findOne({
|
|
offset: Math.floor(Math.random() * (await Tasks.count())),
|
|
});
|
|
const Timesheet2 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Timesheet2?.setTask) {
|
|
await Timesheet2.setTask(relatedTask2);
|
|
}
|
|
|
|
const relatedTask3 = await Tasks.findOne({
|
|
offset: Math.floor(Math.random() * (await Tasks.count())),
|
|
});
|
|
const Timesheet3 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Timesheet3?.setTask) {
|
|
await Timesheet3.setTask(relatedTask3);
|
|
}
|
|
|
|
const relatedTask4 = await Tasks.findOne({
|
|
offset: Math.floor(Math.random() * (await Tasks.count())),
|
|
});
|
|
const Timesheet4 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Timesheet4?.setTask) {
|
|
await Timesheet4.setTask(relatedTask4);
|
|
}
|
|
}
|
|
|
|
async function associateTimesheetWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Timesheet0 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Timesheet0?.setOrganization) {
|
|
await Timesheet0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Timesheet1 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Timesheet1?.setOrganization) {
|
|
await Timesheet1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Timesheet2 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Timesheet2?.setOrganization) {
|
|
await Timesheet2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Timesheet3 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Timesheet3?.setOrganization) {
|
|
await Timesheet3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Timesheet4 = await Timesheets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Timesheet4?.setOrganization) {
|
|
await Timesheet4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Customers.bulkCreate(CustomersData);
|
|
|
|
await Projects.bulkCreate(ProjectsData);
|
|
|
|
await Tasks.bulkCreate(TasksData);
|
|
|
|
await Timesheets.bulkCreate(TimesheetsData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateCustomerWithOrganization(),
|
|
|
|
await associateProjectWithCustomer(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateProjectWithOrganization(),
|
|
|
|
await associateProjectWithOrganization(),
|
|
|
|
await associateTaskWithProject(),
|
|
|
|
await associateTaskWithOrganization(),
|
|
|
|
await associateTimesheetWithUser(),
|
|
|
|
await associateTimesheetWithTask(),
|
|
|
|
await associateTimesheetWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('customers', null, {});
|
|
|
|
await queryInterface.bulkDelete('projects', null, {});
|
|
|
|
await queryInterface.bulkDelete('tasks', null, {});
|
|
|
|
await queryInterface.bulkDelete('timesheets', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|