38747-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-02-24 20:43:44 +00:00

4859 lines
87 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Advertisers = db.advertisers;
const AdCampaigns = db.ad_campaigns;
const Ads = db.ads;
const AdViews = db.ad_views;
const Tasks = db.tasks;
const TaskCompletions = db.task_completions;
const WalletAccounts = db.wallet_accounts;
const WithdrawRequests = db.withdraw_requests;
const Transactions = db.transactions;
const Referrals = db.referrals;
const SupportTickets = db.support_tickets;
const AppSettings = db.app_settings;
const AdvertisersData = [
{
"name": "Caspian Mobile",
"contact_email": "media@caspianmobile.example",
"contact_phone": "+994125550101",
"website": "https://caspianmobile.example",
"status": "active",
"notes": "Consumer mobile carrier brand campaigns",
},
{
"name": "Baku Market",
"contact_email": "ads@bakumarket.example",
"contact_phone": "+994125550202",
"website": "https://bakumarket.example",
"status": "blocked",
"notes": "Retail promotions and seasonal offers",
},
{
"name": "FinTech Nova",
"contact_email": "growth@fintechnova.example",
"contact_phone": "+994125550303",
"website": "https://fintechnova.example",
"status": "active",
"notes": "Fintech app user acquisition pushes",
},
{
"name": "Travel Araz",
"contact_email": "partner@travelaraz.example",
"contact_phone": "+994125550404",
"website": "https://travelaraz.example",
"status": "active",
"notes": "Travel deals and package awareness",
},
];
const AdCampaignsData = [
{
// type code here for "relation_one" field
"name": "Winter Data Bonus",
"description": "Video ads promoting winter data bundles",
"status": "draft",
"start_at": new Date('2026-02-01T00:00:00Z'),
"end_at": new Date('2026-03-01T00:00:00Z'),
"reward_amount": 0.03,
"reward_currency": "USD",
"reward_points": 10,
"daily_cap_views": 20000,
"total_cap_views": 300000,
"target_platform": "ios",
"target_countries": "AZ",
"budget_amount": 4500,
"budget_currency": "AZN",
},
{
// type code here for "relation_one" field
"name": "Weekend Savings",
"description": "Short video promotion for weekend discounts",
"status": "draft",
"start_at": new Date('2026-02-10T00:00:00Z'),
"end_at": new Date('2026-03-10T00:00:00Z'),
"reward_amount": 0.02,
"reward_currency": "EUR",
"reward_points": 7,
"daily_cap_views": 15000,
"total_cap_views": 200000,
"target_platform": "all",
"target_countries": "AZ",
"budget_amount": 3000,
"budget_currency": "USD",
},
{
// type code here for "relation_one" field
"name": "Card Cashback Launch",
"description": "Acquisition campaign for cashback card signup",
"status": "ended",
"start_at": new Date('2026-01-15T00:00:00Z'),
"end_at": new Date('2026-02-28T00:00:00Z'),
"reward_amount": 0.04,
"reward_currency": "AZN",
"reward_points": 15,
"daily_cap_views": 10000,
"total_cap_views": 120000,
"target_platform": "web",
"target_countries": "AZ",
"budget_amount": 3800,
"budget_currency": "EUR",
},
{
// type code here for "relation_one" field
"name": "Spring Getaways",
"description": "Awareness campaign for spring travel packages",
"status": "ended",
"start_at": new Date('2026-03-05T00:00:00Z'),
"end_at": new Date('2026-04-05T00:00:00Z'),
"reward_amount": 0.03,
"reward_currency": "USD",
"reward_points": 12,
"daily_cap_views": 12000,
"total_cap_views": 150000,
"target_platform": "web",
"target_countries": "AZ",
"budget_amount": 4200,
"budget_currency": "AZN",
},
];
const AdsData = [
{
// type code here for "relation_one" field
"title": "Caspian Mobile 15GB Bonus",
"format": "offerwall",
"landing_url": "https://caspianmobile.example/winter",
// type code here for "files" field
// type code here for "images" field
"min_watch_seconds": 20,
"requires_click": false,
"status": "archived",
},
{
// type code here for "relation_one" field
"title": "Baku Market Weekend Deals",
"format": "interstitial",
"landing_url": "https://bakumarket.example/weekend",
// type code here for "files" field
// type code here for "images" field
"min_watch_seconds": 15,
"requires_click": true,
"status": "archived",
},
{
// type code here for "relation_one" field
"title": "FinTech Nova Cashback Card",
"format": "video",
"landing_url": "https://fintechnova.example/cashback",
// type code here for "files" field
// type code here for "images" field
"min_watch_seconds": 10,
"requires_click": true,
"status": "active",
},
{
// type code here for "relation_one" field
"title": "Travel Araz Spring Offer",
"format": "video",
"landing_url": "https://travelaraz.example/spring",
// type code here for "files" field
// type code here for "images" field
"min_watch_seconds": 0,
"requires_click": true,
"status": "archived",
},
];
const AdViewsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"started_at": new Date('2026-02-22T12:10:00Z'),
"completed_at": new Date('2026-02-22T12:10:25Z'),
"watch_seconds": 25,
"state": "completed",
"ip_address": "188.253.10.21",
"device_fingerprint": "fp_nigar_01",
"reward_amount": 0.03,
"reward_currency": "EUR",
"reward_points": 10,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"started_at": new Date('2026-02-21T20:20:00Z'),
"completed_at": new Date('2026-02-21T20:20:18Z'),
"watch_seconds": 18,
"state": "rejected",
"ip_address": "188.253.11.34",
"device_fingerprint": "fp_elvin_02",
"reward_amount": 0.02,
"reward_currency": "AZN",
"reward_points": 7,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"started_at": new Date('2026-02-10T08:00:00Z'),
"completed_at": new Date('2026-02-10T08:00:05Z'),
"watch_seconds": 5,
"state": "completed",
"ip_address": "188.253.12.55",
"device_fingerprint": "fp_kamran_03",
"reward_amount": 0,
"reward_currency": "EUR",
"reward_points": 0,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"started_at": new Date('2026-02-19T16:30:00Z'),
"completed_at": new Date('2026-02-19T16:30:12Z'),
"watch_seconds": 12,
"state": "fraud_suspected",
"ip_address": "188.253.10.21",
"device_fingerprint": "fp_nigar_01",
"reward_amount": 0.03,
"reward_currency": "EUR",
"reward_points": 12,
},
];
const TasksData = [
{
"title": "Daily Login Bonus",
"description": "Log in once per day to receive points",
"task_type": "daily_login",
"status": "active",
"start_at": new Date('2026-02-01T00:00:00Z'),
"end_at": new Date('2026-12-31T23:59:59Z'),
"max_completions_per_user": 365,
"reward_points": 5,
"reward_amount": 0,
"reward_currency": "EUR",
"requirements_text": "Open the app and stay logged in for 10 seconds",
},
{
"title": "Watch 3 Ads",
"description": "Watch three eligible ads in one day",
"task_type": "watch_ad",
"status": "archived",
"start_at": new Date('2026-02-15T00:00:00Z'),
"end_at": new Date('2026-03-15T00:00:00Z'),
"max_completions_per_user": 30,
"reward_points": 20,
"reward_amount": 0,
"reward_currency": "AZN",
"requirements_text": "Complete 3 video ads with full watch time",
},
{
"title": "Survey Feedback",
"description": "Complete a short product feedback survey",
"task_type": "watch_ad",
"status": "archived",
"start_at": new Date('2026-02-20T00:00:00Z'),
"end_at": new Date('2026-03-20T00:00:00Z'),
"max_completions_per_user": 1,
"reward_points": 50,
"reward_amount": 0.1,
"reward_currency": "EUR",
"requirements_text": "Answer all survey questions and submit",
},
{
"title": "Install Partner App",
"description": "Install partner app and open it once",
"task_type": "install_app",
"status": "active",
"start_at": new Date('2026-02-10T00:00:00Z'),
"end_at": new Date('2026-04-10T00:00:00Z'),
"max_completions_per_user": 1,
"reward_points": 120,
"reward_amount": 0.3,
"reward_currency": "USD",
"requirements_text": "Install from official store and open for 15 seconds",
},
];
const TaskCompletionsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"completed_at": new Date('2026-02-22T12:00:05Z'),
"status": "pending",
"proof_text": "App opened and session active",
// type code here for "files" field
"reward_points": 5,
"reward_amount": 0,
"reward_currency": "USD",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"completed_at": new Date('2026-02-21T20:35:00Z'),
"status": "pending",
"proof_text": "Completed 3 ads today",
// type code here for "files" field
"reward_points": 20,
"reward_amount": 0,
"reward_currency": "EUR",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"completed_at": new Date('2026-02-23T10:10:00Z'),
"status": "pending",
"proof_text": "Submitted survey response",
// type code here for "files" field
"reward_points": 50,
"reward_amount": 0.1,
"reward_currency": "EUR",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"completed_at": new Date('2026-02-11T09:00:00Z'),
"status": "rejected",
"proof_text": "Install could not be verified",
// type code here for "files" field
"reward_points": 0,
"reward_amount": 0,
"reward_currency": "AZN",
},
];
const WalletAccountsData = [
{
// type code here for "relation_one" field
"account_type": "iban",
"provider_name": "Kapital Bank",
"account_identifier": "5399 0000 1234 5678",
"account_holder_name": "Nigar Hasanli",
"status": "active",
"is_default": true,
},
{
// type code here for "relation_one" field
"account_type": "crypto",
"provider_name": "ABB",
"account_identifier": "4169 0000 9876 5432",
"account_holder_name": "Elvin Karimov",
"status": "active",
"is_default": true,
},
{
// type code here for "relation_one" field
"account_type": "mobile_wallet",
"provider_name": "Pasha Bank",
"account_identifier": "AZ21PAHA00000000001234567890",
"account_holder_name": "Rashad Aliyev",
"status": "active",
"is_default": true,
},
{
// type code here for "relation_one" field
"account_type": "paypal",
"provider_name": "PayPal",
"account_identifier": "aysel.payments@example.com",
"account_holder_name": "Aysel Mammadova",
"status": "active",
"is_default": true,
},
];
const WithdrawRequestsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"amount": 2,
"currency": "USD",
"status": "pending",
"requested_at": new Date('2026-02-23T14:00:00Z'),
"processed_at": new Date('2026-02-23T14:00:00Z'),
"admin_note": "Pending review",
"external_reference": "WD-2026-0001",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"amount": 1.5,
"currency": "USD",
"status": "rejected",
"requested_at": new Date('2026-02-20T09:00:00Z'),
"processed_at": new Date('2026-02-20T10:30:00Z'),
"admin_note": "Approved for payout batch",
"external_reference": "WD-2026-0002",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"amount": 3.25,
"currency": "AZN",
"status": "approved",
"requested_at": new Date('2026-02-15T13:20:00Z'),
"processed_at": new Date('2026-02-16T08:10:00Z'),
"admin_note": "Paid via bank transfer",
"external_reference": "WD-2026-0003",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"amount": 1,
"currency": "AZN",
"status": "pending",
"requested_at": new Date('2026-02-12T08:30:00Z'),
"processed_at": new Date('2026-02-12T09:00:00Z'),
"admin_note": "Account disabled and verification failed",
"external_reference": "WD-2026-0004",
},
];
const TransactionsData = [
{
// type code here for "relation_one" field
"type": "task_reward",
"direction": "debit",
"amount": 0.03,
"currency": "EUR",
"points": 10,
"description": "Reward for ad view Caspian Mobile 15GB Bonus",
"occurred_at": new Date('2026-02-22T12:10:25Z'),
"status": "posted",
"reference_code": "TX-AV-10001",
},
{
// type code here for "relation_one" field
"type": "referral_bonus",
"direction": "credit",
"amount": 0.05,
"currency": "EUR",
"points": 30,
"description": "Reward for task completion Profile Completion",
"occurred_at": new Date('2026-02-02T11:25:00Z'),
"status": "reversed",
"reference_code": "TX-TK-10002",
},
{
// type code here for "relation_one" field
"type": "withdrawal",
"direction": "credit",
"amount": 0.1,
"currency": "USD",
"points": 25,
"description": "Referral bonus for invited user signup",
"occurred_at": new Date('2026-01-05T09:05:00Z'),
"status": "reversed",
"reference_code": "TX-RF-10003",
},
{
// type code here for "relation_one" field
"type": "task_reward",
"direction": "debit",
"amount": 3.25,
"currency": "EUR",
"points": 0,
"description": "Withdrawal payout WD-2026-0003",
"occurred_at": new Date('2026-02-16T08:10:00Z'),
"status": "pending",
"reference_code": "TX-WD-10004",
},
];
const ReferralsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"referred_at": new Date('2026-01-05T09:00:00Z'),
"status": "qualified",
"bonus_points": 25,
"bonus_amount": 0.1,
"bonus_currency": "AZN",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"referred_at": new Date('2026-02-01T11:20:00Z'),
"status": "cancelled",
"bonus_points": 25,
"bonus_amount": 0.1,
"bonus_currency": "AZN",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"referred_at": new Date('2026-01-20T14:00:00Z'),
"status": "qualified",
"bonus_points": 0,
"bonus_amount": 0,
"bonus_currency": "AZN",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"referred_at": new Date('2026-02-03T10:10:00Z'),
"status": "qualified",
"bonus_points": 25,
"bonus_amount": 0.1,
"bonus_currency": "USD",
},
];
const SupportTicketsData = [
{
// type code here for "relation_one" field
"subject": "Withdrawal pending too long",
"message": "My withdrawal request WD-2026-0001 is still pending. Please advise expected processing time.",
"status": "closed",
"priority": "low",
"opened_at": new Date('2026-02-23T15:10:00Z'),
"closed_at": new Date('2026-02-23T15:10:00Z'),
// type code here for "files" field
"admin_reply": "We are reviewing your request and will update you shortly.",
},
{
// type code here for "relation_one" field
"subject": "Points not added after ads",
"message": "I watched an ad but points were not added to my balance. Please check my activity.",
"status": "open",
"priority": "normal",
"opened_at": new Date('2026-02-21T21:00:00Z'),
"closed_at": new Date('2026-02-21T21:00:00Z'),
// type code here for "files" field
"admin_reply": "We are checking your ad view logs and will respond soon.",
},
{
// type code here for "relation_one" field
"subject": "Account suspension inquiry",
"message": "My account was suspended and I would like to understand the reason and steps to restore access.",
"status": "open",
"priority": "low",
"opened_at": new Date('2026-02-10T10:00:00Z'),
"closed_at": new Date('2026-02-12T09:30:00Z'),
// type code here for "files" field
"admin_reply": "Your account was flagged for invalid activity. Please complete verification to appeal.",
},
{
// type code here for "relation_one" field
"subject": "Update payout method",
"message": "I want to change my payout method from IBAN to card. Please confirm the steps.",
"status": "closed",
"priority": "low",
"opened_at": new Date('2026-02-14T12:30:00Z'),
"closed_at": new Date('2026-02-15T08:00:00Z'),
// type code here for "files" field
"admin_reply": "You can add a new wallet account and set it as default in Wallet settings.",
},
];
const AppSettingsData = [
{
"key": "min_withdraw_amount",
"value": "2.00",
"description": "Minimum withdrawal amount in default currency",
"scope": "private",
},
{
"key": "default_currency",
"value": "AZN",
"description": "Default currency for rewards and payouts",
"scope": "public",
},
{
"key": "referral_bonus_amount",
"value": "0.10",
"description": "Bonus amount paid when referral becomes qualified",
"scope": "private",
},
{
"key": "fraud_watch_seconds_threshold",
"value": "8",
"description": "Minimum watch seconds before considering a view valid",
"scope": "private",
},
];
// Similar logic for "relation_many"
async function associateAdCampaignWithAdvertiser() {
const relatedAdvertiser0 = await Advertisers.findOne({
offset: Math.floor(Math.random() * (await Advertisers.count())),
});
const AdCampaign0 = await AdCampaigns.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AdCampaign0?.setAdvertiser)
{
await
AdCampaign0.
setAdvertiser(relatedAdvertiser0);
}
const relatedAdvertiser1 = await Advertisers.findOne({
offset: Math.floor(Math.random() * (await Advertisers.count())),
});
const AdCampaign1 = await AdCampaigns.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AdCampaign1?.setAdvertiser)
{
await
AdCampaign1.
setAdvertiser(relatedAdvertiser1);
}
const relatedAdvertiser2 = await Advertisers.findOne({
offset: Math.floor(Math.random() * (await Advertisers.count())),
});
const AdCampaign2 = await AdCampaigns.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AdCampaign2?.setAdvertiser)
{
await
AdCampaign2.
setAdvertiser(relatedAdvertiser2);
}
const relatedAdvertiser3 = await Advertisers.findOne({
offset: Math.floor(Math.random() * (await Advertisers.count())),
});
const AdCampaign3 = await AdCampaigns.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (AdCampaign3?.setAdvertiser)
{
await
AdCampaign3.
setAdvertiser(relatedAdvertiser3);
}
}
async function associateAdWithCampaign() {
const relatedCampaign0 = await AdCampaigns.findOne({
offset: Math.floor(Math.random() * (await AdCampaigns.count())),
});
const Ad0 = await Ads.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Ad0?.setCampaign)
{
await
Ad0.
setCampaign(relatedCampaign0);
}
const relatedCampaign1 = await AdCampaigns.findOne({
offset: Math.floor(Math.random() * (await AdCampaigns.count())),
});
const Ad1 = await Ads.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Ad1?.setCampaign)
{
await
Ad1.
setCampaign(relatedCampaign1);
}
const relatedCampaign2 = await AdCampaigns.findOne({
offset: Math.floor(Math.random() * (await AdCampaigns.count())),
});
const Ad2 = await Ads.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Ad2?.setCampaign)
{
await
Ad2.
setCampaign(relatedCampaign2);
}
const relatedCampaign3 = await AdCampaigns.findOne({
offset: Math.floor(Math.random() * (await AdCampaigns.count())),
});
const Ad3 = await Ads.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Ad3?.setCampaign)
{
await
Ad3.
setCampaign(relatedCampaign3);
}
}
async function associateAdViewWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AdView0 = await AdViews.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AdView0?.setUser)
{
await
AdView0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AdView1 = await AdViews.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AdView1?.setUser)
{
await
AdView1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AdView2 = await AdViews.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AdView2?.setUser)
{
await
AdView2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AdView3 = await AdViews.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (AdView3?.setUser)
{
await
AdView3.
setUser(relatedUser3);
}
}
async function associateAdViewWithAd() {
const relatedAd0 = await Ads.findOne({
offset: Math.floor(Math.random() * (await Ads.count())),
});
const AdView0 = await AdViews.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AdView0?.setAd)
{
await
AdView0.
setAd(relatedAd0);
}
const relatedAd1 = await Ads.findOne({
offset: Math.floor(Math.random() * (await Ads.count())),
});
const AdView1 = await AdViews.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AdView1?.setAd)
{
await
AdView1.
setAd(relatedAd1);
}
const relatedAd2 = await Ads.findOne({
offset: Math.floor(Math.random() * (await Ads.count())),
});
const AdView2 = await AdViews.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AdView2?.setAd)
{
await
AdView2.
setAd(relatedAd2);
}
const relatedAd3 = await Ads.findOne({
offset: Math.floor(Math.random() * (await Ads.count())),
});
const AdView3 = await AdViews.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (AdView3?.setAd)
{
await
AdView3.
setAd(relatedAd3);
}
}
async function associateTaskCompletionWithTask() {
const relatedTask0 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const TaskCompletion0 = await TaskCompletions.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (TaskCompletion0?.setTask)
{
await
TaskCompletion0.
setTask(relatedTask0);
}
const relatedTask1 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const TaskCompletion1 = await TaskCompletions.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (TaskCompletion1?.setTask)
{
await
TaskCompletion1.
setTask(relatedTask1);
}
const relatedTask2 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const TaskCompletion2 = await TaskCompletions.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (TaskCompletion2?.setTask)
{
await
TaskCompletion2.
setTask(relatedTask2);
}
const relatedTask3 = await Tasks.findOne({
offset: Math.floor(Math.random() * (await Tasks.count())),
});
const TaskCompletion3 = await TaskCompletions.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (TaskCompletion3?.setTask)
{
await
TaskCompletion3.
setTask(relatedTask3);
}
}
async function associateTaskCompletionWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const TaskCompletion0 = await TaskCompletions.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (TaskCompletion0?.setUser)
{
await
TaskCompletion0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const TaskCompletion1 = await TaskCompletions.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (TaskCompletion1?.setUser)
{
await
TaskCompletion1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const TaskCompletion2 = await TaskCompletions.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (TaskCompletion2?.setUser)
{
await
TaskCompletion2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const TaskCompletion3 = await TaskCompletions.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (TaskCompletion3?.setUser)
{
await
TaskCompletion3.
setUser(relatedUser3);
}
}
async function associateWalletAccountWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WalletAccount0 = await WalletAccounts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (WalletAccount0?.setUser)
{
await
WalletAccount0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WalletAccount1 = await WalletAccounts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (WalletAccount1?.setUser)
{
await
WalletAccount1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WalletAccount2 = await WalletAccounts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (WalletAccount2?.setUser)
{
await
WalletAccount2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WalletAccount3 = await WalletAccounts.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (WalletAccount3?.setUser)
{
await
WalletAccount3.
setUser(relatedUser3);
}
}
async function associateWithdrawRequestWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WithdrawRequest0 = await WithdrawRequests.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (WithdrawRequest0?.setUser)
{
await
WithdrawRequest0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WithdrawRequest1 = await WithdrawRequests.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (WithdrawRequest1?.setUser)
{
await
WithdrawRequest1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WithdrawRequest2 = await WithdrawRequests.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (WithdrawRequest2?.setUser)
{
await
WithdrawRequest2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WithdrawRequest3 = await WithdrawRequests.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (WithdrawRequest3?.setUser)
{
await
WithdrawRequest3.
setUser(relatedUser3);
}
}
async function associateWithdrawRequestWithWallet_account() {
const relatedWallet_account0 = await WalletAccounts.findOne({
offset: Math.floor(Math.random() * (await WalletAccounts.count())),
});
const WithdrawRequest0 = await WithdrawRequests.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (WithdrawRequest0?.setWallet_account)
{
await
WithdrawRequest0.
setWallet_account(relatedWallet_account0);
}
const relatedWallet_account1 = await WalletAccounts.findOne({
offset: Math.floor(Math.random() * (await WalletAccounts.count())),
});
const WithdrawRequest1 = await WithdrawRequests.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (WithdrawRequest1?.setWallet_account)
{
await
WithdrawRequest1.
setWallet_account(relatedWallet_account1);
}
const relatedWallet_account2 = await WalletAccounts.findOne({
offset: Math.floor(Math.random() * (await WalletAccounts.count())),
});
const WithdrawRequest2 = await WithdrawRequests.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (WithdrawRequest2?.setWallet_account)
{
await
WithdrawRequest2.
setWallet_account(relatedWallet_account2);
}
const relatedWallet_account3 = await WalletAccounts.findOne({
offset: Math.floor(Math.random() * (await WalletAccounts.count())),
});
const WithdrawRequest3 = await WithdrawRequests.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (WithdrawRequest3?.setWallet_account)
{
await
WithdrawRequest3.
setWallet_account(relatedWallet_account3);
}
}
async function associateTransactionWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Transaction0 = await Transactions.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Transaction0?.setUser)
{
await
Transaction0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Transaction1 = await Transactions.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Transaction1?.setUser)
{
await
Transaction1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Transaction2 = await Transactions.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Transaction2?.setUser)
{
await
Transaction2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Transaction3 = await Transactions.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Transaction3?.setUser)
{
await
Transaction3.
setUser(relatedUser3);
}
}
async function associateReferralWithReferrer() {
const relatedReferrer0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Referral0 = await Referrals.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Referral0?.setReferrer)
{
await
Referral0.
setReferrer(relatedReferrer0);
}
const relatedReferrer1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Referral1 = await Referrals.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Referral1?.setReferrer)
{
await
Referral1.
setReferrer(relatedReferrer1);
}
const relatedReferrer2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Referral2 = await Referrals.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Referral2?.setReferrer)
{
await
Referral2.
setReferrer(relatedReferrer2);
}
const relatedReferrer3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Referral3 = await Referrals.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Referral3?.setReferrer)
{
await
Referral3.
setReferrer(relatedReferrer3);
}
}
async function associateReferralWithReferred_user() {
const relatedReferred_user0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Referral0 = await Referrals.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Referral0?.setReferred_user)
{
await
Referral0.
setReferred_user(relatedReferred_user0);
}
const relatedReferred_user1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Referral1 = await Referrals.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Referral1?.setReferred_user)
{
await
Referral1.
setReferred_user(relatedReferred_user1);
}
const relatedReferred_user2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Referral2 = await Referrals.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Referral2?.setReferred_user)
{
await
Referral2.
setReferred_user(relatedReferred_user2);
}
const relatedReferred_user3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Referral3 = await Referrals.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (Referral3?.setReferred_user)
{
await
Referral3.
setReferred_user(relatedReferred_user3);
}
}
async function associateSupportTicketWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SupportTicket0 = await SupportTickets.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (SupportTicket0?.setUser)
{
await
SupportTicket0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SupportTicket1 = await SupportTickets.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (SupportTicket1?.setUser)
{
await
SupportTicket1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SupportTicket2 = await SupportTickets.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (SupportTicket2?.setUser)
{
await
SupportTicket2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const SupportTicket3 = await SupportTickets.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (SupportTicket3?.setUser)
{
await
SupportTicket3.
setUser(relatedUser3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Advertisers.bulkCreate(AdvertisersData);
await AdCampaigns.bulkCreate(AdCampaignsData);
await Ads.bulkCreate(AdsData);
await AdViews.bulkCreate(AdViewsData);
await Tasks.bulkCreate(TasksData);
await TaskCompletions.bulkCreate(TaskCompletionsData);
await WalletAccounts.bulkCreate(WalletAccountsData);
await WithdrawRequests.bulkCreate(WithdrawRequestsData);
await Transactions.bulkCreate(TransactionsData);
await Referrals.bulkCreate(ReferralsData);
await SupportTickets.bulkCreate(SupportTicketsData);
await AppSettings.bulkCreate(AppSettingsData);
await Promise.all([
// Similar logic for "relation_many"
await associateAdCampaignWithAdvertiser(),
await associateAdWithCampaign(),
await associateAdViewWithUser(),
await associateAdViewWithAd(),
await associateTaskCompletionWithTask(),
await associateTaskCompletionWithUser(),
await associateWalletAccountWithUser(),
await associateWithdrawRequestWithUser(),
await associateWithdrawRequestWithWallet_account(),
await associateTransactionWithUser(),
await associateReferralWithReferrer(),
await associateReferralWithReferred_user(),
await associateSupportTicketWithUser(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('advertisers', null, {});
await queryInterface.bulkDelete('ad_campaigns', null, {});
await queryInterface.bulkDelete('ads', null, {});
await queryInterface.bulkDelete('ad_views', null, {});
await queryInterface.bulkDelete('tasks', null, {});
await queryInterface.bulkDelete('task_completions', null, {});
await queryInterface.bulkDelete('wallet_accounts', null, {});
await queryInterface.bulkDelete('withdraw_requests', null, {});
await queryInterface.bulkDelete('transactions', null, {});
await queryInterface.bulkDelete('referrals', null, {});
await queryInterface.bulkDelete('support_tickets', null, {});
await queryInterface.bulkDelete('app_settings', null, {});
},
};