937 lines
24 KiB
JavaScript
937 lines
24 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const CarbonOffsets = db.carbon_offsets;
|
|
|
|
const EsgReports = db.esg_reports;
|
|
|
|
const Materials = db.materials;
|
|
|
|
const SmartContracts = db.smart_contracts;
|
|
|
|
const Suppliers = db.suppliers;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const CarbonOffsetsData = [
|
|
{
|
|
project_name: 'Forest Restoration Project',
|
|
|
|
offset_amount: 1000.5,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
project_name: 'Wind Energy Initiative',
|
|
|
|
offset_amount: 2000.75,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
project_name: 'Solar Power Expansion',
|
|
|
|
offset_amount: 1500.25,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
project_name: 'Ocean Cleanup Program',
|
|
|
|
offset_amount: 500,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
project_name: 'Urban Green Spaces',
|
|
|
|
offset_amount: 750,
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const EsgReportsData = [
|
|
{
|
|
title: 'Q1 2023 ESG Report',
|
|
|
|
report_date: new Date('2023-03-31T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Q2 2023 ESG Report',
|
|
|
|
report_date: new Date('2023-06-30T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Q3 2023 ESG Report',
|
|
|
|
report_date: new Date('2023-09-30T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Q4 2023 ESG Report',
|
|
|
|
report_date: new Date('2023-12-31T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Annual 2023 ESG Report',
|
|
|
|
report_date: new Date('2023-12-31T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const MaterialsData = [
|
|
{
|
|
name: 'Recycled Plastic',
|
|
|
|
source: 'Green Earth Supplies',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Organic Cotton',
|
|
|
|
source: 'Eco Friendly Co',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Bamboo Fiber',
|
|
|
|
source: 'Sustainable Goods Ltd',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Recycled Aluminum',
|
|
|
|
source: 'Renewable Resources Inc',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Hemp Fabric',
|
|
|
|
source: 'Earthwise Products',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SmartContractsData = [
|
|
{
|
|
contract_name: 'Supplier Agreement 2023',
|
|
|
|
start_date: new Date('2023-01-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-12-31T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
contract_name: 'Eco Partnership 2023',
|
|
|
|
start_date: new Date('2023-02-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-30T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
contract_name: 'Sustainability Contract 2023',
|
|
|
|
start_date: new Date('2023-03-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-10-31T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
contract_name: 'Green Deal 2023',
|
|
|
|
start_date: new Date('2023-04-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-09-30T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
contract_name: 'Renewable Agreement 2023',
|
|
|
|
start_date: new Date('2023-05-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-08-31T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SuppliersData = [
|
|
{
|
|
name: 'Green Earth Supplies',
|
|
|
|
contact_information: '123 Green St, Eco City, EC 12345',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Eco Friendly Co',
|
|
|
|
contact_information: '456 Eco Rd, Green Town, GT 67890',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Sustainable Goods Ltd',
|
|
|
|
contact_information: '789 Sustainable Ave, Nature City, NC 11223',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Renewable Resources Inc',
|
|
|
|
contact_information: '101 Renewable Blvd, Clean City, CC 33445',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Earthwise Products',
|
|
|
|
contact_information: '202 Earthwise Ln, Planet Town, PT 55667',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'Karl Landsteiner',
|
|
},
|
|
|
|
{
|
|
name: 'John Dalton',
|
|
},
|
|
|
|
{
|
|
name: 'Paul Dirac',
|
|
},
|
|
|
|
{
|
|
name: 'Linus Pauling',
|
|
},
|
|
|
|
{
|
|
name: 'Noam Chomsky',
|
|
},
|
|
];
|
|
|
|
// 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 associateCarbonOffsetWithSupplier() {
|
|
const relatedSupplier0 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const CarbonOffset0 = await CarbonOffsets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (CarbonOffset0?.setSupplier) {
|
|
await CarbonOffset0.setSupplier(relatedSupplier0);
|
|
}
|
|
|
|
const relatedSupplier1 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const CarbonOffset1 = await CarbonOffsets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (CarbonOffset1?.setSupplier) {
|
|
await CarbonOffset1.setSupplier(relatedSupplier1);
|
|
}
|
|
|
|
const relatedSupplier2 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const CarbonOffset2 = await CarbonOffsets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (CarbonOffset2?.setSupplier) {
|
|
await CarbonOffset2.setSupplier(relatedSupplier2);
|
|
}
|
|
|
|
const relatedSupplier3 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const CarbonOffset3 = await CarbonOffsets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (CarbonOffset3?.setSupplier) {
|
|
await CarbonOffset3.setSupplier(relatedSupplier3);
|
|
}
|
|
|
|
const relatedSupplier4 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const CarbonOffset4 = await CarbonOffsets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (CarbonOffset4?.setSupplier) {
|
|
await CarbonOffset4.setSupplier(relatedSupplier4);
|
|
}
|
|
}
|
|
|
|
async function associateCarbonOffsetWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CarbonOffset0 = await CarbonOffsets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (CarbonOffset0?.setOrganization) {
|
|
await CarbonOffset0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CarbonOffset1 = await CarbonOffsets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (CarbonOffset1?.setOrganization) {
|
|
await CarbonOffset1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CarbonOffset2 = await CarbonOffsets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (CarbonOffset2?.setOrganization) {
|
|
await CarbonOffset2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CarbonOffset3 = await CarbonOffsets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (CarbonOffset3?.setOrganization) {
|
|
await CarbonOffset3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CarbonOffset4 = await CarbonOffsets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (CarbonOffset4?.setOrganization) {
|
|
await CarbonOffset4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateEsgReportWithAuditor() {
|
|
const relatedAuditor0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const EsgReport0 = await EsgReports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (EsgReport0?.setAuditor) {
|
|
await EsgReport0.setAuditor(relatedAuditor0);
|
|
}
|
|
|
|
const relatedAuditor1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const EsgReport1 = await EsgReports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (EsgReport1?.setAuditor) {
|
|
await EsgReport1.setAuditor(relatedAuditor1);
|
|
}
|
|
|
|
const relatedAuditor2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const EsgReport2 = await EsgReports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (EsgReport2?.setAuditor) {
|
|
await EsgReport2.setAuditor(relatedAuditor2);
|
|
}
|
|
|
|
const relatedAuditor3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const EsgReport3 = await EsgReports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (EsgReport3?.setAuditor) {
|
|
await EsgReport3.setAuditor(relatedAuditor3);
|
|
}
|
|
|
|
const relatedAuditor4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const EsgReport4 = await EsgReports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (EsgReport4?.setAuditor) {
|
|
await EsgReport4.setAuditor(relatedAuditor4);
|
|
}
|
|
}
|
|
|
|
async function associateEsgReportWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const EsgReport0 = await EsgReports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (EsgReport0?.setOrganization) {
|
|
await EsgReport0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const EsgReport1 = await EsgReports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (EsgReport1?.setOrganization) {
|
|
await EsgReport1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const EsgReport2 = await EsgReports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (EsgReport2?.setOrganization) {
|
|
await EsgReport2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const EsgReport3 = await EsgReports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (EsgReport3?.setOrganization) {
|
|
await EsgReport3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const EsgReport4 = await EsgReports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (EsgReport4?.setOrganization) {
|
|
await EsgReport4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateMaterialWithSupplier() {
|
|
const relatedSupplier0 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const Material0 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Material0?.setSupplier) {
|
|
await Material0.setSupplier(relatedSupplier0);
|
|
}
|
|
|
|
const relatedSupplier1 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const Material1 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Material1?.setSupplier) {
|
|
await Material1.setSupplier(relatedSupplier1);
|
|
}
|
|
|
|
const relatedSupplier2 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const Material2 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Material2?.setSupplier) {
|
|
await Material2.setSupplier(relatedSupplier2);
|
|
}
|
|
|
|
const relatedSupplier3 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const Material3 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Material3?.setSupplier) {
|
|
await Material3.setSupplier(relatedSupplier3);
|
|
}
|
|
|
|
const relatedSupplier4 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const Material4 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Material4?.setSupplier) {
|
|
await Material4.setSupplier(relatedSupplier4);
|
|
}
|
|
}
|
|
|
|
async function associateMaterialWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Material0 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Material0?.setOrganization) {
|
|
await Material0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Material1 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Material1?.setOrganization) {
|
|
await Material1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Material2 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Material2?.setOrganization) {
|
|
await Material2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Material3 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Material3?.setOrganization) {
|
|
await Material3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Material4 = await Materials.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Material4?.setOrganization) {
|
|
await Material4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateSmartContractWithSupplier() {
|
|
const relatedSupplier0 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const SmartContract0 = await SmartContracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (SmartContract0?.setSupplier) {
|
|
await SmartContract0.setSupplier(relatedSupplier0);
|
|
}
|
|
|
|
const relatedSupplier1 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const SmartContract1 = await SmartContracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (SmartContract1?.setSupplier) {
|
|
await SmartContract1.setSupplier(relatedSupplier1);
|
|
}
|
|
|
|
const relatedSupplier2 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const SmartContract2 = await SmartContracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (SmartContract2?.setSupplier) {
|
|
await SmartContract2.setSupplier(relatedSupplier2);
|
|
}
|
|
|
|
const relatedSupplier3 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const SmartContract3 = await SmartContracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (SmartContract3?.setSupplier) {
|
|
await SmartContract3.setSupplier(relatedSupplier3);
|
|
}
|
|
|
|
const relatedSupplier4 = await Suppliers.findOne({
|
|
offset: Math.floor(Math.random() * (await Suppliers.count())),
|
|
});
|
|
const SmartContract4 = await SmartContracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (SmartContract4?.setSupplier) {
|
|
await SmartContract4.setSupplier(relatedSupplier4);
|
|
}
|
|
}
|
|
|
|
async function associateSmartContractWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const SmartContract0 = await SmartContracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (SmartContract0?.setOrganization) {
|
|
await SmartContract0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const SmartContract1 = await SmartContracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (SmartContract1?.setOrganization) {
|
|
await SmartContract1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const SmartContract2 = await SmartContracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (SmartContract2?.setOrganization) {
|
|
await SmartContract2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const SmartContract3 = await SmartContracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (SmartContract3?.setOrganization) {
|
|
await SmartContract3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const SmartContract4 = await SmartContracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (SmartContract4?.setOrganization) {
|
|
await SmartContract4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateSupplierWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Supplier0 = await Suppliers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Supplier0?.setOrganization) {
|
|
await Supplier0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Supplier1 = await Suppliers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Supplier1?.setOrganization) {
|
|
await Supplier1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Supplier2 = await Suppliers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Supplier2?.setOrganization) {
|
|
await Supplier2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Supplier3 = await Suppliers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Supplier3?.setOrganization) {
|
|
await Supplier3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Supplier4 = await Suppliers.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Supplier4?.setOrganization) {
|
|
await Supplier4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await CarbonOffsets.bulkCreate(CarbonOffsetsData);
|
|
|
|
await EsgReports.bulkCreate(EsgReportsData);
|
|
|
|
await Materials.bulkCreate(MaterialsData);
|
|
|
|
await SmartContracts.bulkCreate(SmartContractsData);
|
|
|
|
await Suppliers.bulkCreate(SuppliersData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
await associateCarbonOffsetWithSupplier(),
|
|
|
|
await associateCarbonOffsetWithOrganization(),
|
|
|
|
await associateEsgReportWithAuditor(),
|
|
|
|
await associateEsgReportWithOrganization(),
|
|
|
|
await associateMaterialWithSupplier(),
|
|
|
|
await associateMaterialWithOrganization(),
|
|
|
|
await associateSmartContractWithSupplier(),
|
|
|
|
await associateSmartContractWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateSupplierWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('carbon_offsets', null, {});
|
|
|
|
await queryInterface.bulkDelete('esg_reports', null, {});
|
|
|
|
await queryInterface.bulkDelete('materials', null, {});
|
|
|
|
await queryInterface.bulkDelete('smart_contracts', null, {});
|
|
|
|
await queryInterface.bulkDelete('suppliers', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|