1055 lines
26 KiB
JavaScript
1055 lines
26 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Activities = db.activities;
|
|
|
|
const Appraisals = db.appraisals;
|
|
|
|
const Clients = db.clients;
|
|
|
|
const Invoices = db.invoices;
|
|
|
|
const Messages = db.messages;
|
|
|
|
const Notifications = db.notifications;
|
|
|
|
const Orders = db.orders;
|
|
|
|
const Properties = db.properties;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const ActivitiesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
action: 'Created new order for Prime Realty.',
|
|
|
|
timestamp: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
action: 'Reviewed appraisal report for 456 Oak Blvd.',
|
|
|
|
timestamp: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
action: 'Updated property details for 789 Pine St.',
|
|
|
|
timestamp: new Date('2023-10-03T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const AppraisalsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
accepted_date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
delivery_date: new Date('2023-10-05T17:00:00Z'),
|
|
|
|
status: 'assigned',
|
|
|
|
fee: 1500,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
accepted_date: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
delivery_date: new Date('2023-10-06T16:00:00Z'),
|
|
|
|
status: 'assigned',
|
|
|
|
fee: 2000,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
accepted_date: new Date('2023-10-03T11:00:00Z'),
|
|
|
|
delivery_date: new Date('2023-10-07T15:00:00Z'),
|
|
|
|
status: 'delivered',
|
|
|
|
fee: 2500,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ClientsData = [
|
|
{
|
|
name: 'Prime Realty',
|
|
|
|
contact_email: 'info@primerealty.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Urban Appraisals',
|
|
|
|
contact_email: 'support@urbanappraisals.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Metro Valuations',
|
|
|
|
contact_email: 'hello@metrovaluations.com',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const InvoicesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
total_amount: 1500,
|
|
|
|
issue_date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
due_date: new Date('2023-10-15T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
total_amount: 2000,
|
|
|
|
issue_date: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
due_date: new Date('2023-10-16T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
total_amount: 2500,
|
|
|
|
issue_date: new Date('2023-10-03T11:00:00Z'),
|
|
|
|
due_date: new Date('2023-10-17T17:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const MessagesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'Please review the latest appraisal report.',
|
|
|
|
sent_date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'Make sure to update the property details.',
|
|
|
|
sent_date: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'The order has been scheduled for inspection.',
|
|
|
|
sent_date: new Date('2023-10-03T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const NotificationsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'New order received from Prime Realty.',
|
|
|
|
date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'Appraisal report ready for review.',
|
|
|
|
date: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'Inspection scheduled for 789 Pine St.',
|
|
|
|
date: new Date('2023-10-03T11:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrdersData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
requested_date: new Date('2023-10-01T09:00:00Z'),
|
|
|
|
status: 'scheduled',
|
|
|
|
fee: 1500,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
requested_date: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
status: 'delivered',
|
|
|
|
fee: 2000,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
requested_date: new Date('2023-10-03T11:00:00Z'),
|
|
|
|
status: 'delivered',
|
|
|
|
fee: 2500,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PropertiesData = [
|
|
{
|
|
address: '123 Maple Ave, Anytown, USA',
|
|
|
|
property_type: 'Residential',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
address: '456 Oak Blvd, Othertown, USA',
|
|
|
|
property_type: 'Commercial',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
address: '789 Pine St, Bigcity, USA',
|
|
|
|
property_type: 'Industrial',
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'Veracity Real Estate Solutions',
|
|
},
|
|
|
|
{
|
|
name: 'Prime Realty',
|
|
},
|
|
|
|
{
|
|
name: 'Urban Appraisals',
|
|
},
|
|
];
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
async function associateActivityWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Activity0 = await Activities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Activity0?.setUser) {
|
|
await Activity0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Activity1 = await Activities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Activity1?.setUser) {
|
|
await Activity1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Activity2 = await Activities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Activity2?.setUser) {
|
|
await Activity2.setUser(relatedUser2);
|
|
}
|
|
}
|
|
|
|
async function associateActivityWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Activity0 = await Activities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Activity0?.setOrganization) {
|
|
await Activity0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Activity1 = await Activities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Activity1?.setOrganization) {
|
|
await Activity1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Activity2 = await Activities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Activity2?.setOrganization) {
|
|
await Activity2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
async function associateAppraisalWithProperty() {
|
|
const relatedProperty0 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Appraisal0 = await Appraisals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Appraisal0?.setProperty) {
|
|
await Appraisal0.setProperty(relatedProperty0);
|
|
}
|
|
|
|
const relatedProperty1 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Appraisal1 = await Appraisals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Appraisal1?.setProperty) {
|
|
await Appraisal1.setProperty(relatedProperty1);
|
|
}
|
|
|
|
const relatedProperty2 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Appraisal2 = await Appraisals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Appraisal2?.setProperty) {
|
|
await Appraisal2.setProperty(relatedProperty2);
|
|
}
|
|
}
|
|
|
|
async function associateAppraisalWithAppraiser() {
|
|
const relatedAppraiser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Appraisal0 = await Appraisals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Appraisal0?.setAppraiser) {
|
|
await Appraisal0.setAppraiser(relatedAppraiser0);
|
|
}
|
|
|
|
const relatedAppraiser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Appraisal1 = await Appraisals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Appraisal1?.setAppraiser) {
|
|
await Appraisal1.setAppraiser(relatedAppraiser1);
|
|
}
|
|
|
|
const relatedAppraiser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Appraisal2 = await Appraisals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Appraisal2?.setAppraiser) {
|
|
await Appraisal2.setAppraiser(relatedAppraiser2);
|
|
}
|
|
}
|
|
|
|
async function associateAppraisalWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Appraisal0 = await Appraisals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Appraisal0?.setOrganization) {
|
|
await Appraisal0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Appraisal1 = await Appraisals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Appraisal1?.setOrganization) {
|
|
await Appraisal1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Appraisal2 = await Appraisals.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Appraisal2?.setOrganization) {
|
|
await Appraisal2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateClientWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Client0 = await Clients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Client0?.setOrganization) {
|
|
await Client0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Client1 = await Clients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Client1?.setOrganization) {
|
|
await Client1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Client2 = await Clients.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Client2?.setOrganization) {
|
|
await Client2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
async function associateInvoiceWithClient() {
|
|
const relatedClient0 = await Clients.findOne({
|
|
offset: Math.floor(Math.random() * (await Clients.count())),
|
|
});
|
|
const Invoice0 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Invoice0?.setClient) {
|
|
await Invoice0.setClient(relatedClient0);
|
|
}
|
|
|
|
const relatedClient1 = await Clients.findOne({
|
|
offset: Math.floor(Math.random() * (await Clients.count())),
|
|
});
|
|
const Invoice1 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Invoice1?.setClient) {
|
|
await Invoice1.setClient(relatedClient1);
|
|
}
|
|
|
|
const relatedClient2 = await Clients.findOne({
|
|
offset: Math.floor(Math.random() * (await Clients.count())),
|
|
});
|
|
const Invoice2 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Invoice2?.setClient) {
|
|
await Invoice2.setClient(relatedClient2);
|
|
}
|
|
}
|
|
|
|
async function associateInvoiceWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Invoice0 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Invoice0?.setOrganization) {
|
|
await Invoice0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Invoice1 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Invoice1?.setOrganization) {
|
|
await Invoice1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Invoice2 = await Invoices.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Invoice2?.setOrganization) {
|
|
await Invoice2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
async function associateMessageWithSender() {
|
|
const relatedSender0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setSender) {
|
|
await Message0.setSender(relatedSender0);
|
|
}
|
|
|
|
const relatedSender1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setSender) {
|
|
await Message1.setSender(relatedSender1);
|
|
}
|
|
|
|
const relatedSender2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setSender) {
|
|
await Message2.setSender(relatedSender2);
|
|
}
|
|
}
|
|
|
|
async function associateMessageWithRecipient() {
|
|
const relatedRecipient0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setRecipient) {
|
|
await Message0.setRecipient(relatedRecipient0);
|
|
}
|
|
|
|
const relatedRecipient1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setRecipient) {
|
|
await Message1.setRecipient(relatedRecipient1);
|
|
}
|
|
|
|
const relatedRecipient2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setRecipient) {
|
|
await Message2.setRecipient(relatedRecipient2);
|
|
}
|
|
}
|
|
|
|
async function associateMessageWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setOrganization) {
|
|
await Message0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setOrganization) {
|
|
await Message1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setOrganization) {
|
|
await Message2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
async function associateNotificationWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification0 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Notification0?.setUser) {
|
|
await Notification0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification1 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Notification1?.setUser) {
|
|
await Notification1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification2 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Notification2?.setUser) {
|
|
await Notification2.setUser(relatedUser2);
|
|
}
|
|
}
|
|
|
|
async function associateNotificationWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Notification0 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Notification0?.setOrganization) {
|
|
await Notification0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Notification1 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Notification1?.setOrganization) {
|
|
await Notification1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Notification2 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Notification2?.setOrganization) {
|
|
await Notification2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
async function associateOrderWithClient() {
|
|
const relatedClient0 = await Clients.findOne({
|
|
offset: Math.floor(Math.random() * (await Clients.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setClient) {
|
|
await Order0.setClient(relatedClient0);
|
|
}
|
|
|
|
const relatedClient1 = await Clients.findOne({
|
|
offset: Math.floor(Math.random() * (await Clients.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setClient) {
|
|
await Order1.setClient(relatedClient1);
|
|
}
|
|
|
|
const relatedClient2 = await Clients.findOne({
|
|
offset: Math.floor(Math.random() * (await Clients.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setClient) {
|
|
await Order2.setClient(relatedClient2);
|
|
}
|
|
}
|
|
|
|
async function associateOrderWithProperty() {
|
|
const relatedProperty0 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setProperty) {
|
|
await Order0.setProperty(relatedProperty0);
|
|
}
|
|
|
|
const relatedProperty1 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setProperty) {
|
|
await Order1.setProperty(relatedProperty1);
|
|
}
|
|
|
|
const relatedProperty2 = await Properties.findOne({
|
|
offset: Math.floor(Math.random() * (await Properties.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setProperty) {
|
|
await Order2.setProperty(relatedProperty2);
|
|
}
|
|
}
|
|
|
|
async function associateOrderWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Order0 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Order0?.setOrganization) {
|
|
await Order0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Order1 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Order1?.setOrganization) {
|
|
await Order1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Order2 = await Orders.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Order2?.setOrganization) {
|
|
await Order2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associatePropertyWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Property0 = await Properties.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Property0?.setOrganization) {
|
|
await Property0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Property1 = await Properties.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Property1?.setOrganization) {
|
|
await Property1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Property2 = await Properties.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Property2?.setOrganization) {
|
|
await Property2.setOrganization(relatedOrganization2);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Activities.bulkCreate(ActivitiesData);
|
|
|
|
await Appraisals.bulkCreate(AppraisalsData);
|
|
|
|
await Clients.bulkCreate(ClientsData);
|
|
|
|
await Invoices.bulkCreate(InvoicesData);
|
|
|
|
await Messages.bulkCreate(MessagesData);
|
|
|
|
await Notifications.bulkCreate(NotificationsData);
|
|
|
|
await Orders.bulkCreate(OrdersData);
|
|
|
|
await Properties.bulkCreate(PropertiesData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
await associateActivityWithUser(),
|
|
|
|
await associateActivityWithOrganization(),
|
|
|
|
await associateAppraisalWithProperty(),
|
|
|
|
await associateAppraisalWithAppraiser(),
|
|
|
|
await associateAppraisalWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateClientWithOrganization(),
|
|
|
|
await associateInvoiceWithClient(),
|
|
|
|
await associateInvoiceWithOrganization(),
|
|
|
|
await associateMessageWithSender(),
|
|
|
|
await associateMessageWithRecipient(),
|
|
|
|
await associateMessageWithOrganization(),
|
|
|
|
await associateNotificationWithUser(),
|
|
|
|
await associateNotificationWithOrganization(),
|
|
|
|
await associateOrderWithClient(),
|
|
|
|
await associateOrderWithProperty(),
|
|
|
|
await associateOrderWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associatePropertyWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('activities', null, {});
|
|
|
|
await queryInterface.bulkDelete('appraisals', null, {});
|
|
|
|
await queryInterface.bulkDelete('clients', null, {});
|
|
|
|
await queryInterface.bulkDelete('invoices', null, {});
|
|
|
|
await queryInterface.bulkDelete('messages', null, {});
|
|
|
|
await queryInterface.bulkDelete('notifications', null, {});
|
|
|
|
await queryInterface.bulkDelete('orders', null, {});
|
|
|
|
await queryInterface.bulkDelete('properties', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|