1282 lines
31 KiB
JavaScript
1282 lines
31 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const CheckIns = db.check_ins;
|
|
|
|
const Classes = db.classes;
|
|
|
|
const Contracts = db.contracts;
|
|
|
|
const Members = db.members;
|
|
|
|
const Notifications = db.notifications;
|
|
|
|
const Payments = db.payments;
|
|
|
|
const Plans = db.plans;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const CheckInsData = [
|
|
{
|
|
check_in_time: new Date('2023-11-01T09:05:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
check_in_time: new Date('2023-11-02T11:10:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
check_in_time: new Date('2023-11-03T18:15:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
check_in_time: new Date('2023-11-04T17:20:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
check_in_time: new Date('2023-11-05T07:25:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ClassesData = [
|
|
{
|
|
title: 'Yoga Basics',
|
|
|
|
start_time: new Date('2023-11-01T09:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Advanced Pilates',
|
|
|
|
start_time: new Date('2023-11-02T11:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-02T12:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'HIIT Workout',
|
|
|
|
start_time: new Date('2023-11-03T18:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-03T19:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Zumba Dance',
|
|
|
|
start_time: new Date('2023-11-04T17:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-04T18:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'CrossFit Challenge',
|
|
|
|
start_time: new Date('2023-11-05T07:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-05T08:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ContractsData = [
|
|
{
|
|
contract_number: 'C-001',
|
|
|
|
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_number: 'C-002',
|
|
|
|
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_number: 'C-003',
|
|
|
|
start_date: new Date('2023-03-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_number: 'C-004',
|
|
|
|
start_date: new Date('2023-04-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_number: 'C-005',
|
|
|
|
start_date: new Date('2023-05-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
|
|
},
|
|
];
|
|
|
|
const MembersData = [
|
|
{
|
|
first_name: 'Alice',
|
|
|
|
last_name: 'Johnson',
|
|
|
|
email: 'alice.johnson@example.com',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Robert',
|
|
|
|
last_name: 'Miller',
|
|
|
|
email: 'robert.miller@example.com',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Sophia',
|
|
|
|
last_name: 'Davis',
|
|
|
|
email: 'sophia.davis@example.com',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'James',
|
|
|
|
last_name: 'Garcia',
|
|
|
|
email: 'james.garcia@example.com',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
first_name: 'Olivia',
|
|
|
|
last_name: 'Martinez',
|
|
|
|
email: 'olivia.martinez@example.com',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const NotificationsData = [
|
|
{
|
|
message: 'Welcome to FitLife Gym!',
|
|
|
|
sent_at: new Date('2023-10-01T08:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
message: 'Your class starts in 1 hour.',
|
|
|
|
sent_at: new Date('2023-10-02T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
message: 'Payment received. Thank you!',
|
|
|
|
sent_at: new Date('2023-10-03T12:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
message: 'New class schedule available.',
|
|
|
|
sent_at: new Date('2023-10-04T14:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
message: 'Happy Birthday from WellnessWorks!',
|
|
|
|
sent_at: new Date('2023-10-05T16:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PaymentsData = [
|
|
{
|
|
amount: 29.99,
|
|
|
|
payment_date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 49.99,
|
|
|
|
payment_date: new Date('2023-10-02T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 69.99,
|
|
|
|
payment_date: new Date('2023-10-03T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 99.99,
|
|
|
|
payment_date: new Date('2023-10-04T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
amount: 19.99,
|
|
|
|
payment_date: new Date('2023-10-05T00:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PlansData = [
|
|
{
|
|
name: 'Basic Plan',
|
|
|
|
price: 29.99,
|
|
|
|
duration: 3,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Standard Plan',
|
|
|
|
price: 49.99,
|
|
|
|
duration: 6,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Premium Plan',
|
|
|
|
price: 69.99,
|
|
|
|
duration: 12,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Family Plan',
|
|
|
|
price: 99.99,
|
|
|
|
duration: 12,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Student Plan',
|
|
|
|
price: 19.99,
|
|
|
|
duration: 3,
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'FitLife Gym',
|
|
},
|
|
|
|
{
|
|
name: 'HealthHub Studio',
|
|
},
|
|
|
|
{
|
|
name: 'ActiveZone Center',
|
|
},
|
|
|
|
{
|
|
name: 'WellnessWorks',
|
|
},
|
|
|
|
{
|
|
name: 'EnergyFit Club',
|
|
},
|
|
];
|
|
|
|
// 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 associateCheckInWithMember() {
|
|
const relatedMember0 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const CheckIn0 = await CheckIns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (CheckIn0?.setMember) {
|
|
await CheckIn0.setMember(relatedMember0);
|
|
}
|
|
|
|
const relatedMember1 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const CheckIn1 = await CheckIns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (CheckIn1?.setMember) {
|
|
await CheckIn1.setMember(relatedMember1);
|
|
}
|
|
|
|
const relatedMember2 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const CheckIn2 = await CheckIns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (CheckIn2?.setMember) {
|
|
await CheckIn2.setMember(relatedMember2);
|
|
}
|
|
|
|
const relatedMember3 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const CheckIn3 = await CheckIns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (CheckIn3?.setMember) {
|
|
await CheckIn3.setMember(relatedMember3);
|
|
}
|
|
|
|
const relatedMember4 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const CheckIn4 = await CheckIns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (CheckIn4?.setMember) {
|
|
await CheckIn4.setMember(relatedMember4);
|
|
}
|
|
}
|
|
|
|
async function associateCheckInWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CheckIn0 = await CheckIns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (CheckIn0?.setOrganization) {
|
|
await CheckIn0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CheckIn1 = await CheckIns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (CheckIn1?.setOrganization) {
|
|
await CheckIn1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CheckIn2 = await CheckIns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (CheckIn2?.setOrganization) {
|
|
await CheckIn2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CheckIn3 = await CheckIns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (CheckIn3?.setOrganization) {
|
|
await CheckIn3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const CheckIn4 = await CheckIns.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (CheckIn4?.setOrganization) {
|
|
await CheckIn4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateClassWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Class0 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Class0?.setOrganization) {
|
|
await Class0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Class1 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Class1?.setOrganization) {
|
|
await Class1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Class2 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Class2?.setOrganization) {
|
|
await Class2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Class3 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Class3?.setOrganization) {
|
|
await Class3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Class4 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Class4?.setOrganization) {
|
|
await Class4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateContractWithMember() {
|
|
const relatedMember0 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Contract0 = await Contracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Contract0?.setMember) {
|
|
await Contract0.setMember(relatedMember0);
|
|
}
|
|
|
|
const relatedMember1 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Contract1 = await Contracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Contract1?.setMember) {
|
|
await Contract1.setMember(relatedMember1);
|
|
}
|
|
|
|
const relatedMember2 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Contract2 = await Contracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Contract2?.setMember) {
|
|
await Contract2.setMember(relatedMember2);
|
|
}
|
|
|
|
const relatedMember3 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Contract3 = await Contracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Contract3?.setMember) {
|
|
await Contract3.setMember(relatedMember3);
|
|
}
|
|
|
|
const relatedMember4 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Contract4 = await Contracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Contract4?.setMember) {
|
|
await Contract4.setMember(relatedMember4);
|
|
}
|
|
}
|
|
|
|
async function associateContractWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Contract0 = await Contracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Contract0?.setOrganization) {
|
|
await Contract0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Contract1 = await Contracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Contract1?.setOrganization) {
|
|
await Contract1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Contract2 = await Contracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Contract2?.setOrganization) {
|
|
await Contract2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Contract3 = await Contracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Contract3?.setOrganization) {
|
|
await Contract3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Contract4 = await Contracts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Contract4?.setOrganization) {
|
|
await Contract4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateMemberWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Member0 = await Members.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Member0?.setOrganization) {
|
|
await Member0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Member1 = await Members.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Member1?.setOrganization) {
|
|
await Member1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Member2 = await Members.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Member2?.setOrganization) {
|
|
await Member2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Member3 = await Members.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Member3?.setOrganization) {
|
|
await Member3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Member4 = await Members.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Member4?.setOrganization) {
|
|
await Member4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateMemberWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Member0 = await Members.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Member0?.setOrganization) {
|
|
await Member0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Member1 = await Members.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Member1?.setOrganization) {
|
|
await Member1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Member2 = await Members.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Member2?.setOrganization) {
|
|
await Member2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Member3 = await Members.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Member3?.setOrganization) {
|
|
await Member3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Member4 = await Members.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Member4?.setOrganization) {
|
|
await Member4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateNotificationWithMember() {
|
|
const relatedMember0 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Notification0 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Notification0?.setMember) {
|
|
await Notification0.setMember(relatedMember0);
|
|
}
|
|
|
|
const relatedMember1 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Notification1 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Notification1?.setMember) {
|
|
await Notification1.setMember(relatedMember1);
|
|
}
|
|
|
|
const relatedMember2 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Notification2 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Notification2?.setMember) {
|
|
await Notification2.setMember(relatedMember2);
|
|
}
|
|
|
|
const relatedMember3 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Notification3 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Notification3?.setMember) {
|
|
await Notification3.setMember(relatedMember3);
|
|
}
|
|
|
|
const relatedMember4 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Notification4 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Notification4?.setMember) {
|
|
await Notification4.setMember(relatedMember4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Notification3 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Notification3?.setOrganization) {
|
|
await Notification3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Notification4 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Notification4?.setOrganization) {
|
|
await Notification4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associatePaymentWithMember() {
|
|
const relatedMember0 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setMember) {
|
|
await Payment0.setMember(relatedMember0);
|
|
}
|
|
|
|
const relatedMember1 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setMember) {
|
|
await Payment1.setMember(relatedMember1);
|
|
}
|
|
|
|
const relatedMember2 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setMember) {
|
|
await Payment2.setMember(relatedMember2);
|
|
}
|
|
|
|
const relatedMember3 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Payment3 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Payment3?.setMember) {
|
|
await Payment3.setMember(relatedMember3);
|
|
}
|
|
|
|
const relatedMember4 = await Members.findOne({
|
|
offset: Math.floor(Math.random() * (await Members.count())),
|
|
});
|
|
const Payment4 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Payment4?.setMember) {
|
|
await Payment4.setMember(relatedMember4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associatePlanWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Plan0 = await Plans.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Plan0?.setOrganization) {
|
|
await Plan0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Plan1 = await Plans.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Plan1?.setOrganization) {
|
|
await Plan1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Plan2 = await Plans.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Plan2?.setOrganization) {
|
|
await Plan2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Plan3 = await Plans.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Plan3?.setOrganization) {
|
|
await Plan3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Plan4 = await Plans.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Plan4?.setOrganization) {
|
|
await Plan4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await CheckIns.bulkCreate(CheckInsData);
|
|
|
|
await Classes.bulkCreate(ClassesData);
|
|
|
|
await Contracts.bulkCreate(ContractsData);
|
|
|
|
await Members.bulkCreate(MembersData);
|
|
|
|
await Notifications.bulkCreate(NotificationsData);
|
|
|
|
await Payments.bulkCreate(PaymentsData);
|
|
|
|
await Plans.bulkCreate(PlansData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
await associateCheckInWithMember(),
|
|
|
|
await associateCheckInWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateClassWithOrganization(),
|
|
|
|
await associateContractWithMember(),
|
|
|
|
await associateContractWithOrganization(),
|
|
|
|
await associateMemberWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateMemberWithOrganization(),
|
|
|
|
await associateNotificationWithMember(),
|
|
|
|
await associateNotificationWithOrganization(),
|
|
|
|
await associatePaymentWithMember(),
|
|
|
|
await associatePaymentWithOrganization(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associatePlanWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('check_ins', null, {});
|
|
|
|
await queryInterface.bulkDelete('classes', null, {});
|
|
|
|
await queryInterface.bulkDelete('contracts', null, {});
|
|
|
|
await queryInterface.bulkDelete('members', null, {});
|
|
|
|
await queryInterface.bulkDelete('notifications', null, {});
|
|
|
|
await queryInterface.bulkDelete('payments', null, {});
|
|
|
|
await queryInterface.bulkDelete('plans', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|