1454 lines
34 KiB
JavaScript
1454 lines
34 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const ClassRegistrations = db.class_registrations;
|
|
|
|
const Classes = db.classes;
|
|
|
|
const Memberships = db.memberships;
|
|
|
|
const Payments = db.payments;
|
|
|
|
const Products = db.products;
|
|
|
|
const Sales = db.sales;
|
|
|
|
const UserMemberships = db.user_memberships;
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const ClassRegistrationsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
attendance: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
attendance: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
attendance: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
attendance: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
attendance: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ClassesData = [
|
|
{
|
|
name: 'Yoga Basics',
|
|
|
|
description: 'Beginner yoga class focusing on flexibility.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
schedule_date: new Date('2023-10-10'),
|
|
|
|
start_time: new Date('09:00'),
|
|
|
|
end_time: new Date('10:00'),
|
|
|
|
capacity: 20,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'HIIT Workout',
|
|
|
|
description: 'High-intensity interval training for all levels.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
schedule_date: new Date('2023-10-11'),
|
|
|
|
start_time: new Date('18:00'),
|
|
|
|
end_time: new Date('19:00'),
|
|
|
|
capacity: 15,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Pilates Core',
|
|
|
|
description: 'Strengthen your core with Pilates exercises.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
schedule_date: new Date('2023-10-12'),
|
|
|
|
start_time: new Date('11:00'),
|
|
|
|
end_time: new Date('12:00'),
|
|
|
|
capacity: 10,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Zumba Dance',
|
|
|
|
description: 'Dance your way to fitness with Zumba.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
schedule_date: new Date('2023-10-13'),
|
|
|
|
start_time: new Date('17:00'),
|
|
|
|
end_time: new Date('18:00'),
|
|
|
|
capacity: 25,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Spin Class',
|
|
|
|
description: 'Cardio workout on stationary bikes.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
schedule_date: new Date('2023-10-14'),
|
|
|
|
start_time: new Date('07:00'),
|
|
|
|
end_time: new Date('08:00'),
|
|
|
|
capacity: 30,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const MembershipsData = [
|
|
{
|
|
name: 'Basic Plan',
|
|
|
|
description: 'Access to gym facilities during off-peak hours.',
|
|
|
|
price: 29.99,
|
|
|
|
duration: 'Monthly',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Standard Plan',
|
|
|
|
description: 'Full access to gym facilities and group classes.',
|
|
|
|
price: 49.99,
|
|
|
|
duration: 'Yearly',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Premium Plan',
|
|
|
|
description: 'Includes personal training sessions and spa access.',
|
|
|
|
price: 79.99,
|
|
|
|
duration: 'Monthly',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Annual Plan',
|
|
|
|
description: 'Yearly membership with a discount.',
|
|
|
|
price: 499.99,
|
|
|
|
duration: 'Monthly',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Family Plan',
|
|
|
|
description: 'Membership for up to four family members.',
|
|
|
|
price: 99.99,
|
|
|
|
duration: 'Yearly',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const PaymentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
payment_date: new Date('2023-09-01'),
|
|
|
|
amount: 49.99,
|
|
|
|
payment_method: 'PayPal',
|
|
|
|
transaction_id: 'txn_001',
|
|
|
|
payment_type: 'Membership',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
payment_date: new Date('2023-09-05'),
|
|
|
|
amount: 29.99,
|
|
|
|
payment_method: 'Stripe',
|
|
|
|
transaction_id: 'txn_002',
|
|
|
|
payment_type: 'Product',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
payment_date: new Date('2023-09-10'),
|
|
|
|
amount: 79.99,
|
|
|
|
payment_method: 'PayPal',
|
|
|
|
transaction_id: 'txn_003',
|
|
|
|
payment_type: 'Membership',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
payment_date: new Date('2023-09-15'),
|
|
|
|
amount: 99.99,
|
|
|
|
payment_method: 'PayPal',
|
|
|
|
transaction_id: 'txn_004',
|
|
|
|
payment_type: 'Product',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
payment_date: new Date('2023-09-20'),
|
|
|
|
amount: 49.99,
|
|
|
|
payment_method: 'PayPal',
|
|
|
|
transaction_id: 'txn_005',
|
|
|
|
payment_type: 'Product',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ProductsData = [
|
|
{
|
|
name: 'Protein Shake',
|
|
|
|
description: 'Nutritional protein shake for post-workout recovery.',
|
|
|
|
price: 5.99,
|
|
|
|
stock_quantity: 100,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Yoga Mat',
|
|
|
|
description: 'Non-slip yoga mat for all levels.',
|
|
|
|
price: 19.99,
|
|
|
|
stock_quantity: 50,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Dumbbell Set',
|
|
|
|
description: 'Adjustable dumbbell set for strength training.',
|
|
|
|
price: 49.99,
|
|
|
|
stock_quantity: 30,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Gym Towel',
|
|
|
|
description: 'Absorbent towel for gym use.',
|
|
|
|
price: 9.99,
|
|
|
|
stock_quantity: 200,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'Water Bottle',
|
|
|
|
description: 'Reusable water bottle with gym logo.',
|
|
|
|
price: 14.99,
|
|
|
|
stock_quantity: 150,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const SalesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 2,
|
|
|
|
sale_date: new Date('2023-09-01'),
|
|
|
|
total_amount: 11.98,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 1,
|
|
|
|
sale_date: new Date('2023-09-05'),
|
|
|
|
total_amount: 19.99,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 1,
|
|
|
|
sale_date: new Date('2023-09-10'),
|
|
|
|
total_amount: 49.99,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 3,
|
|
|
|
sale_date: new Date('2023-09-15'),
|
|
|
|
total_amount: 29.97,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
quantity: 1,
|
|
|
|
sale_date: new Date('2023-09-20'),
|
|
|
|
total_amount: 14.99,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const UserMembershipsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-01-01'),
|
|
|
|
end_date: new Date('2023-12-31'),
|
|
|
|
active: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-02-01'),
|
|
|
|
end_date: new Date('2023-08-01'),
|
|
|
|
active: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-03-01'),
|
|
|
|
end_date: new Date('2023-09-01'),
|
|
|
|
active: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-04-01'),
|
|
|
|
end_date: new Date('2024-04-01'),
|
|
|
|
active: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-05-01'),
|
|
|
|
end_date: new Date('2023-11-01'),
|
|
|
|
active: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const OrganizationsData = [
|
|
{
|
|
name: 'Max Delbruck',
|
|
},
|
|
|
|
{
|
|
name: 'Paul Ehrlich',
|
|
},
|
|
|
|
{
|
|
name: 'Edward Teller',
|
|
},
|
|
|
|
{
|
|
name: 'Galileo Galilei',
|
|
},
|
|
|
|
{
|
|
name: 'Albrecht von Haller',
|
|
},
|
|
];
|
|
|
|
// 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 associateClassRegistrationWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ClassRegistration0 = await ClassRegistrations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (ClassRegistration0?.setUser) {
|
|
await ClassRegistration0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ClassRegistration1 = await ClassRegistrations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (ClassRegistration1?.setUser) {
|
|
await ClassRegistration1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ClassRegistration2 = await ClassRegistrations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (ClassRegistration2?.setUser) {
|
|
await ClassRegistration2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ClassRegistration3 = await ClassRegistrations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (ClassRegistration3?.setUser) {
|
|
await ClassRegistration3.setUser(relatedUser3);
|
|
}
|
|
|
|
const relatedUser4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ClassRegistration4 = await ClassRegistrations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (ClassRegistration4?.setUser) {
|
|
await ClassRegistration4.setUser(relatedUser4);
|
|
}
|
|
}
|
|
|
|
async function associateClassRegistrationWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ClassRegistration0 = await ClassRegistrations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (ClassRegistration0?.setOrganization) {
|
|
await ClassRegistration0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ClassRegistration1 = await ClassRegistrations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (ClassRegistration1?.setOrganization) {
|
|
await ClassRegistration1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ClassRegistration2 = await ClassRegistrations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (ClassRegistration2?.setOrganization) {
|
|
await ClassRegistration2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ClassRegistration3 = await ClassRegistrations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (ClassRegistration3?.setOrganization) {
|
|
await ClassRegistration3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ClassRegistration4 = await ClassRegistrations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (ClassRegistration4?.setOrganization) {
|
|
await ClassRegistration4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateClassWithTrainer() {
|
|
const relatedTrainer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Class0 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Class0?.setTrainer) {
|
|
await Class0.setTrainer(relatedTrainer0);
|
|
}
|
|
|
|
const relatedTrainer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Class1 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Class1?.setTrainer) {
|
|
await Class1.setTrainer(relatedTrainer1);
|
|
}
|
|
|
|
const relatedTrainer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Class2 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Class2?.setTrainer) {
|
|
await Class2.setTrainer(relatedTrainer2);
|
|
}
|
|
|
|
const relatedTrainer3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Class3 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Class3?.setTrainer) {
|
|
await Class3.setTrainer(relatedTrainer3);
|
|
}
|
|
|
|
const relatedTrainer4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Class4 = await Classes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Class4?.setTrainer) {
|
|
await Class4.setTrainer(relatedTrainer4);
|
|
}
|
|
}
|
|
|
|
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 associateMembershipWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Membership0 = await Memberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Membership0?.setOrganization) {
|
|
await Membership0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Membership1 = await Memberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Membership1?.setOrganization) {
|
|
await Membership1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Membership2 = await Memberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Membership2?.setOrganization) {
|
|
await Membership2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Membership3 = await Memberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Membership3?.setOrganization) {
|
|
await Membership3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Membership4 = await Memberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Membership4?.setOrganization) {
|
|
await Membership4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associatePaymentWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setUser) {
|
|
await Payment0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setUser) {
|
|
await Payment1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setUser) {
|
|
await Payment2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Payment3 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Payment3?.setUser) {
|
|
await Payment3.setUser(relatedUser3);
|
|
}
|
|
|
|
const relatedUser4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Payment4 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Payment4?.setUser) {
|
|
await Payment4.setUser(relatedUser4);
|
|
}
|
|
}
|
|
|
|
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 associateProductWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product0 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Product0?.setOrganization) {
|
|
await Product0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product1 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Product1?.setOrganization) {
|
|
await Product1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product2 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Product2?.setOrganization) {
|
|
await Product2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product3 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Product3?.setOrganization) {
|
|
await Product3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Product4 = await Products.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Product4?.setOrganization) {
|
|
await Product4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setUser) {
|
|
await Sale0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setUser) {
|
|
await Sale1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setUser) {
|
|
await Sale2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Sale3 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Sale3?.setUser) {
|
|
await Sale3.setUser(relatedUser3);
|
|
}
|
|
|
|
const relatedUser4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Sale4 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Sale4?.setUser) {
|
|
await Sale4.setUser(relatedUser4);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithProduct() {
|
|
const relatedProduct0 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setProduct) {
|
|
await Sale0.setProduct(relatedProduct0);
|
|
}
|
|
|
|
const relatedProduct1 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setProduct) {
|
|
await Sale1.setProduct(relatedProduct1);
|
|
}
|
|
|
|
const relatedProduct2 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setProduct) {
|
|
await Sale2.setProduct(relatedProduct2);
|
|
}
|
|
|
|
const relatedProduct3 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Sale3 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Sale3?.setProduct) {
|
|
await Sale3.setProduct(relatedProduct3);
|
|
}
|
|
|
|
const relatedProduct4 = await Products.findOne({
|
|
offset: Math.floor(Math.random() * (await Products.count())),
|
|
});
|
|
const Sale4 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Sale4?.setProduct) {
|
|
await Sale4.setProduct(relatedProduct4);
|
|
}
|
|
}
|
|
|
|
async function associateSaleWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale0 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Sale0?.setOrganization) {
|
|
await Sale0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale1 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Sale1?.setOrganization) {
|
|
await Sale1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale2 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Sale2?.setOrganization) {
|
|
await Sale2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale3 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Sale3?.setOrganization) {
|
|
await Sale3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Sale4 = await Sales.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Sale4?.setOrganization) {
|
|
await Sale4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
async function associateUserMembershipWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserMembership0 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (UserMembership0?.setUser) {
|
|
await UserMembership0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserMembership1 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (UserMembership1?.setUser) {
|
|
await UserMembership1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserMembership2 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (UserMembership2?.setUser) {
|
|
await UserMembership2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserMembership3 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (UserMembership3?.setUser) {
|
|
await UserMembership3.setUser(relatedUser3);
|
|
}
|
|
|
|
const relatedUser4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserMembership4 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (UserMembership4?.setUser) {
|
|
await UserMembership4.setUser(relatedUser4);
|
|
}
|
|
}
|
|
|
|
async function associateUserMembershipWithMembership() {
|
|
const relatedMembership0 = await Memberships.findOne({
|
|
offset: Math.floor(Math.random() * (await Memberships.count())),
|
|
});
|
|
const UserMembership0 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (UserMembership0?.setMembership) {
|
|
await UserMembership0.setMembership(relatedMembership0);
|
|
}
|
|
|
|
const relatedMembership1 = await Memberships.findOne({
|
|
offset: Math.floor(Math.random() * (await Memberships.count())),
|
|
});
|
|
const UserMembership1 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (UserMembership1?.setMembership) {
|
|
await UserMembership1.setMembership(relatedMembership1);
|
|
}
|
|
|
|
const relatedMembership2 = await Memberships.findOne({
|
|
offset: Math.floor(Math.random() * (await Memberships.count())),
|
|
});
|
|
const UserMembership2 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (UserMembership2?.setMembership) {
|
|
await UserMembership2.setMembership(relatedMembership2);
|
|
}
|
|
|
|
const relatedMembership3 = await Memberships.findOne({
|
|
offset: Math.floor(Math.random() * (await Memberships.count())),
|
|
});
|
|
const UserMembership3 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (UserMembership3?.setMembership) {
|
|
await UserMembership3.setMembership(relatedMembership3);
|
|
}
|
|
|
|
const relatedMembership4 = await Memberships.findOne({
|
|
offset: Math.floor(Math.random() * (await Memberships.count())),
|
|
});
|
|
const UserMembership4 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (UserMembership4?.setMembership) {
|
|
await UserMembership4.setMembership(relatedMembership4);
|
|
}
|
|
}
|
|
|
|
async function associateUserMembershipWithOrganization() {
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const UserMembership0 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (UserMembership0?.setOrganization) {
|
|
await UserMembership0.setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const UserMembership1 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (UserMembership1?.setOrganization) {
|
|
await UserMembership1.setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const UserMembership2 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (UserMembership2?.setOrganization) {
|
|
await UserMembership2.setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
const relatedOrganization3 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const UserMembership3 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (UserMembership3?.setOrganization) {
|
|
await UserMembership3.setOrganization(relatedOrganization3);
|
|
}
|
|
|
|
const relatedOrganization4 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const UserMembership4 = await UserMemberships.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (UserMembership4?.setOrganization) {
|
|
await UserMembership4.setOrganization(relatedOrganization4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await ClassRegistrations.bulkCreate(ClassRegistrationsData);
|
|
|
|
await Classes.bulkCreate(ClassesData);
|
|
|
|
await Memberships.bulkCreate(MembershipsData);
|
|
|
|
await Payments.bulkCreate(PaymentsData);
|
|
|
|
await Products.bulkCreate(ProductsData);
|
|
|
|
await Sales.bulkCreate(SalesData);
|
|
|
|
await UserMemberships.bulkCreate(UserMembershipsData);
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
await associateClassRegistrationWithUser(),
|
|
|
|
await associateClassRegistrationWithOrganization(),
|
|
|
|
await associateClassWithTrainer(),
|
|
|
|
await associateClassWithOrganization(),
|
|
|
|
await associateMembershipWithOrganization(),
|
|
|
|
await associatePaymentWithUser(),
|
|
|
|
await associatePaymentWithOrganization(),
|
|
|
|
await associateProductWithOrganization(),
|
|
|
|
await associateSaleWithUser(),
|
|
|
|
await associateSaleWithProduct(),
|
|
|
|
await associateSaleWithOrganization(),
|
|
|
|
await associateUserMembershipWithUser(),
|
|
|
|
await associateUserMembershipWithMembership(),
|
|
|
|
await associateUserMembershipWithOrganization(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('class_registrations', null, {});
|
|
|
|
await queryInterface.bulkDelete('classes', null, {});
|
|
|
|
await queryInterface.bulkDelete('memberships', null, {});
|
|
|
|
await queryInterface.bulkDelete('payments', null, {});
|
|
|
|
await queryInterface.bulkDelete('products', null, {});
|
|
|
|
await queryInterface.bulkDelete('sales', null, {});
|
|
|
|
await queryInterface.bulkDelete('user_memberships', null, {});
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
},
|
|
};
|