1096 lines
26 KiB
JavaScript
1096 lines
26 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Documents = db.documents;
|
|
|
|
const FieldSitePaymentRequisitions = db.field_site_payment_requisitions;
|
|
|
|
const Payments = db.payments;
|
|
|
|
const Projects = db.projects;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const DocumentsData = [
|
|
{
|
|
document_number: 'DOC001',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
document_type: 'RV',
|
|
|
|
prepared_by: 'jdoe',
|
|
|
|
status: 'Filed',
|
|
|
|
cash_balance: true,
|
|
|
|
payment_date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
amount: 1000,
|
|
|
|
shelf_number: 'S001',
|
|
|
|
approved_by: 'asmith',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
document_number: 'DOC002',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
document_type: 'JV',
|
|
|
|
prepared_by: 'asmith',
|
|
|
|
status: 'InProgress',
|
|
|
|
cash_balance: false,
|
|
|
|
payment_date: new Date('2023-10-02T11:00:00Z'),
|
|
|
|
amount: 2000,
|
|
|
|
shelf_number: 'S002',
|
|
|
|
approved_by: 'bwhite',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
document_number: 'DOC003',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
document_type: 'RV',
|
|
|
|
prepared_by: 'bwhite',
|
|
|
|
status: 'InProgress',
|
|
|
|
cash_balance: true,
|
|
|
|
payment_date: new Date('2023-10-03T12:00:00Z'),
|
|
|
|
amount: 1500,
|
|
|
|
shelf_number: 'S003',
|
|
|
|
approved_by: 'cgreen',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
document_number: 'DOC004',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
document_type: 'BPV',
|
|
|
|
prepared_by: 'cgreen',
|
|
|
|
status: 'InProgress',
|
|
|
|
cash_balance: true,
|
|
|
|
payment_date: new Date('2023-10-04T13:00:00Z'),
|
|
|
|
amount: 2500,
|
|
|
|
shelf_number: 'S004',
|
|
|
|
approved_by: 'dblack',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
document_number: 'DOC005',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
document_type: 'BPV',
|
|
|
|
prepared_by: 'dblack',
|
|
|
|
status: 'InProgress',
|
|
|
|
cash_balance: true,
|
|
|
|
payment_date: new Date('2023-10-05T14:00:00Z'),
|
|
|
|
amount: 3000,
|
|
|
|
shelf_number: 'S005',
|
|
|
|
approved_by: 'jdoe',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const FieldSitePaymentRequisitionsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
department: 'Finance',
|
|
|
|
employee_name: 'John Doe',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
departure_place: 'New York',
|
|
|
|
departure_date: new Date('2023-10-01T08:00:00Z'),
|
|
|
|
arrival_place: 'London',
|
|
|
|
return_date: new Date('2023-10-10T18:00:00Z'),
|
|
|
|
requisition_date: new Date('2023-09-25T09:00:00Z'),
|
|
|
|
requested_amount: 5000,
|
|
|
|
payment_type: 'JV',
|
|
|
|
status: 'Paid',
|
|
|
|
requester: 'jdoe',
|
|
|
|
approver: 'asmith',
|
|
|
|
due_date: new Date('2023-10-15T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
department: 'Legal',
|
|
|
|
employee_name: 'Alice Smith',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
departure_place: 'Los Angeles',
|
|
|
|
departure_date: new Date('2023-10-02T09:00:00Z'),
|
|
|
|
arrival_place: 'Paris',
|
|
|
|
return_date: new Date('2023-10-12T19:00:00Z'),
|
|
|
|
requisition_date: new Date('2023-09-26T10:00:00Z'),
|
|
|
|
requested_amount: 6000,
|
|
|
|
payment_type: 'JV',
|
|
|
|
status: 'Pending',
|
|
|
|
requester: 'asmith',
|
|
|
|
approver: 'bwhite',
|
|
|
|
due_date: new Date('2023-10-16T18:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
department: 'Audit',
|
|
|
|
employee_name: 'Bob White',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
departure_place: 'Chicago',
|
|
|
|
departure_date: new Date('2023-10-03T10:00:00Z'),
|
|
|
|
arrival_place: 'Berlin',
|
|
|
|
return_date: new Date('2023-10-13T20:00:00Z'),
|
|
|
|
requisition_date: new Date('2023-09-27T11:00:00Z'),
|
|
|
|
requested_amount: 7000,
|
|
|
|
payment_type: 'BPV',
|
|
|
|
status: 'Paid',
|
|
|
|
requester: 'bwhite',
|
|
|
|
approver: 'cgreen',
|
|
|
|
due_date: new Date('2023-10-17T19:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
department: 'Operations',
|
|
|
|
employee_name: 'Charlie Green',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
departure_place: 'Houston',
|
|
|
|
departure_date: new Date('2023-10-04T11:00:00Z'),
|
|
|
|
arrival_place: 'Tokyo',
|
|
|
|
return_date: new Date('2023-10-14T21:00:00Z'),
|
|
|
|
requisition_date: new Date('2023-09-28T12:00:00Z'),
|
|
|
|
requested_amount: 8000,
|
|
|
|
payment_type: 'JV',
|
|
|
|
status: 'Paid',
|
|
|
|
requester: 'cgreen',
|
|
|
|
approver: 'dblack',
|
|
|
|
due_date: new Date('2023-10-18T20:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
department: 'Investments',
|
|
|
|
employee_name: 'David Black',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
departure_place: 'Miami',
|
|
|
|
departure_date: new Date('2023-10-05T12:00:00Z'),
|
|
|
|
arrival_place: 'Sydney',
|
|
|
|
return_date: new Date('2023-10-15T22:00:00Z'),
|
|
|
|
requisition_date: new Date('2023-09-29T13:00:00Z'),
|
|
|
|
requested_amount: 9000,
|
|
|
|
payment_type: 'JV',
|
|
|
|
status: 'Approved',
|
|
|
|
requester: 'dblack',
|
|
|
|
approver: 'jdoe',
|
|
|
|
due_date: new Date('2023-10-19T21:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PaymentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
amount: 500,
|
|
|
|
payment_type: 'Subtraction',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2023-10-02T11:00:00Z'),
|
|
|
|
amount: 1000,
|
|
|
|
payment_type: 'Addition',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2023-10-03T12:00:00Z'),
|
|
|
|
amount: 750,
|
|
|
|
payment_type: 'Subtraction',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2023-10-04T13:00:00Z'),
|
|
|
|
amount: 1250,
|
|
|
|
payment_type: 'Addition',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
date: new Date('2023-10-05T14:00:00Z'),
|
|
|
|
amount: 1500,
|
|
|
|
payment_type: 'Subtraction',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ProjectsData = [
|
|
{
|
|
name: 'Project Alpha',
|
|
|
|
code: 'PA001',
|
|
|
|
type: 'MOH',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Project Beta',
|
|
|
|
code: 'PB002',
|
|
|
|
type: 'CDC',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Project Gamma',
|
|
|
|
code: 'PG003',
|
|
|
|
type: 'CDC',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Project Delta',
|
|
|
|
code: 'PD004',
|
|
|
|
type: 'Other',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Project Epsilon',
|
|
|
|
code: 'PE005',
|
|
|
|
type: 'MOH',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'Global Finance Inc.',
|
|
},
|
|
|
|
{
|
|
name: 'Legal Solutions Ltd.',
|
|
},
|
|
|
|
{
|
|
name: 'Financial Services Group',
|
|
},
|
|
|
|
{
|
|
name: 'Corporate Finance Co.',
|
|
},
|
|
|
|
{
|
|
name: 'Investment Partners',
|
|
},
|
|
];
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
async function associateDocumentWithProject() {
|
|
const relatedProject0 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Document0 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Document0?.setProject) {
|
|
await Document0.setProject(relatedProject0);
|
|
}
|
|
|
|
const relatedProject1 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Document1 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Document1?.setProject) {
|
|
await Document1.setProject(relatedProject1);
|
|
}
|
|
|
|
const relatedProject2 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Document2 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Document2?.setProject) {
|
|
await Document2.setProject(relatedProject2);
|
|
}
|
|
|
|
const relatedProject3 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Document3 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Document3?.setProject) {
|
|
await Document3.setProject(relatedProject3);
|
|
}
|
|
|
|
const relatedProject4 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Document4 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Document4?.setProject) {
|
|
await Document4.setProject(relatedProject4);
|
|
}
|
|
}
|
|
|
|
async function associateDocumentWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Document0 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Document0?.setOrganization) {
|
|
await Document0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Document1 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Document1?.setOrganization) {
|
|
await Document1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Document2 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Document2?.setOrganization) {
|
|
await Document2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Document3 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Document3?.setOrganization) {
|
|
await Document3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Document4 = await Documents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Document4?.setOrganization) {
|
|
await Document4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateFieldSitePaymentRequisitionWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const FieldSitePaymentRequisition0 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (FieldSitePaymentRequisition0?.setOrganization) {
|
|
await FieldSitePaymentRequisition0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const FieldSitePaymentRequisition1 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (FieldSitePaymentRequisition1?.setOrganization) {
|
|
await FieldSitePaymentRequisition1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const FieldSitePaymentRequisition2 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (FieldSitePaymentRequisition2?.setOrganization) {
|
|
await FieldSitePaymentRequisition2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const FieldSitePaymentRequisition3 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (FieldSitePaymentRequisition3?.setOrganization) {
|
|
await FieldSitePaymentRequisition3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const FieldSitePaymentRequisition4 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (FieldSitePaymentRequisition4?.setOrganization) {
|
|
await FieldSitePaymentRequisition4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateFieldSitePaymentRequisitionWithProject() {
|
|
const relatedProject0 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const FieldSitePaymentRequisition0 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (FieldSitePaymentRequisition0?.setProject) {
|
|
await FieldSitePaymentRequisition0.setProject(relatedProject0);
|
|
}
|
|
|
|
const relatedProject1 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const FieldSitePaymentRequisition1 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (FieldSitePaymentRequisition1?.setProject) {
|
|
await FieldSitePaymentRequisition1.setProject(relatedProject1);
|
|
}
|
|
|
|
const relatedProject2 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const FieldSitePaymentRequisition2 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (FieldSitePaymentRequisition2?.setProject) {
|
|
await FieldSitePaymentRequisition2.setProject(relatedProject2);
|
|
}
|
|
|
|
const relatedProject3 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const FieldSitePaymentRequisition3 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (FieldSitePaymentRequisition3?.setProject) {
|
|
await FieldSitePaymentRequisition3.setProject(relatedProject3);
|
|
}
|
|
|
|
const relatedProject4 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const FieldSitePaymentRequisition4 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (FieldSitePaymentRequisition4?.setProject) {
|
|
await FieldSitePaymentRequisition4.setProject(relatedProject4);
|
|
}
|
|
}
|
|
|
|
async function associateFieldSitePaymentRequisitionWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const FieldSitePaymentRequisition0 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (FieldSitePaymentRequisition0?.setOrganization) {
|
|
await FieldSitePaymentRequisition0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const FieldSitePaymentRequisition1 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (FieldSitePaymentRequisition1?.setOrganization) {
|
|
await FieldSitePaymentRequisition1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const FieldSitePaymentRequisition2 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (FieldSitePaymentRequisition2?.setOrganization) {
|
|
await FieldSitePaymentRequisition2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const FieldSitePaymentRequisition3 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (FieldSitePaymentRequisition3?.setOrganization) {
|
|
await FieldSitePaymentRequisition3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const FieldSitePaymentRequisition4 =
|
|
await FieldSitePaymentRequisitions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (FieldSitePaymentRequisition4?.setOrganization) {
|
|
await FieldSitePaymentRequisition4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associatePaymentWithDocument() {
|
|
const relatedDocument0 = await Documents.findOne({
|
|
offset: Math.floor(Math.random() * (await Documents.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setDocument) {
|
|
await Payment0.setDocument(relatedDocument0);
|
|
}
|
|
|
|
const relatedDocument1 = await Documents.findOne({
|
|
offset: Math.floor(Math.random() * (await Documents.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setDocument) {
|
|
await Payment1.setDocument(relatedDocument1);
|
|
}
|
|
|
|
const relatedDocument2 = await Documents.findOne({
|
|
offset: Math.floor(Math.random() * (await Documents.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setDocument) {
|
|
await Payment2.setDocument(relatedDocument2);
|
|
}
|
|
|
|
const relatedDocument3 = await Documents.findOne({
|
|
offset: Math.floor(Math.random() * (await Documents.count())),
|
|
});
|
|
const Payment3 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Payment3?.setDocument) {
|
|
await Payment3.setDocument(relatedDocument3);
|
|
}
|
|
|
|
const relatedDocument4 = await Documents.findOne({
|
|
offset: Math.floor(Math.random() * (await Documents.count())),
|
|
});
|
|
const Payment4 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Payment4?.setDocument) {
|
|
await Payment4.setDocument(relatedDocument4);
|
|
}
|
|
}
|
|
|
|
async function associatePaymentWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setOrganization) {
|
|
await Payment0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setOrganization) {
|
|
await Payment1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setOrganization) {
|
|
await Payment2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Payment3 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Payment3?.setOrganization) {
|
|
await Payment3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Payment4 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Payment4?.setOrganization) {
|
|
await Payment4.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 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);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Documents.bulkCreate(DocumentsData);
|
|
|
|
await FieldSitePaymentRequisitions.bulkCreate(
|
|
FieldSitePaymentRequisitionsData,
|
|
);
|
|
|
|
await Payments.bulkCreate(PaymentsData);
|
|
|
|
await Projects.bulkCreate(ProjectsData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
await associateDocumentWithProject(),
|
|
|
|
await associateDocumentWithOrganization(),
|
|
|
|
await associateFieldSitePaymentRequisitionWithOrganization(),
|
|
|
|
await associateFieldSitePaymentRequisitionWithProject(),
|
|
|
|
await associateFieldSitePaymentRequisitionWithOrganization(),
|
|
|
|
await associatePaymentWithDocument(),
|
|
|
|
await associatePaymentWithOrganization(),
|
|
|
|
await associateProjectWithOrganization(),
|
|
|
|
await associateProjectWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('documents', null, {});
|
|
|
|
await queryInterface.bulkDelete(
|
|
'field_site_payment_requisitions',
|
|
null,
|
|
{},
|
|
);
|
|
|
|
await queryInterface.bulkDelete('payments', null, {});
|
|
|
|
await queryInterface.bulkDelete('projects', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|