383 lines
7.5 KiB
JavaScript
383 lines
7.5 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const ProductivityTools = db.productivity_tools;
|
|
|
|
const Rewards = db.rewards;
|
|
|
|
const Tasks = db.tasks;
|
|
|
|
const Transactions = db.transactions;
|
|
|
|
const Wallets = db.wallets;
|
|
|
|
const ProductivityToolsData = [
|
|
{
|
|
tool_name: 'Image Compressor',
|
|
|
|
reward_points: 20,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
tool_name: 'Smart Calculator',
|
|
|
|
reward_points: 25,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
tool_name: 'Profit Calculator',
|
|
|
|
reward_points: 30,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
tool_name: 'Reels Video Editor',
|
|
|
|
reward_points: 35,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const RewardsData = [
|
|
{
|
|
name: 'Amazon Gift Card',
|
|
|
|
points_required: 100,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'PayPal Cash',
|
|
|
|
points_required: 150,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Starbucks Voucher',
|
|
|
|
points_required: 50,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Netflix Subscription',
|
|
|
|
points_required: 200,
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const TasksData = [
|
|
{
|
|
title: 'Complete Survey',
|
|
|
|
task_type: 'video',
|
|
|
|
points: 50,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Visit Partner Website',
|
|
|
|
task_type: 'website',
|
|
|
|
points: 30,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Watch Tutorial Video',
|
|
|
|
task_type: 'website',
|
|
|
|
points: 40,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Use Image Compressor',
|
|
|
|
task_type: 'video',
|
|
|
|
points: 20,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TransactionsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
points: 50,
|
|
|
|
transaction_type: 'spent',
|
|
|
|
transaction_date: new Date('2023-10-01T10:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
points: 30,
|
|
|
|
transaction_type: 'transferred',
|
|
|
|
transaction_date: new Date('2023-10-02T11:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
points: 40,
|
|
|
|
transaction_type: 'earned',
|
|
|
|
transaction_date: new Date('2023-10-03T12:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
points: 20,
|
|
|
|
transaction_type: 'spent',
|
|
|
|
transaction_date: new Date('2023-10-04T13:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const WalletsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
balance: 150,
|
|
|
|
qr_wallet_id: 'QR123',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
balance: 120,
|
|
|
|
qr_wallet_id: 'QR456',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
balance: 140,
|
|
|
|
qr_wallet_id: 'QR789',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
balance: 110,
|
|
|
|
qr_wallet_id: 'QR101',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateTaskWithAssigned_user() {
|
|
const relatedAssigned_user0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Task0 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Task0?.setAssigned_user) {
|
|
await Task0.setAssigned_user(relatedAssigned_user0);
|
|
}
|
|
|
|
const relatedAssigned_user1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Task1 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Task1?.setAssigned_user) {
|
|
await Task1.setAssigned_user(relatedAssigned_user1);
|
|
}
|
|
|
|
const relatedAssigned_user2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Task2 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Task2?.setAssigned_user) {
|
|
await Task2.setAssigned_user(relatedAssigned_user2);
|
|
}
|
|
|
|
const relatedAssigned_user3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Task3 = await Tasks.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Task3?.setAssigned_user) {
|
|
await Task3.setAssigned_user(relatedAssigned_user3);
|
|
}
|
|
}
|
|
|
|
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 associateWalletWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Wallet0 = await Wallets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Wallet0?.setUser) {
|
|
await Wallet0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Wallet1 = await Wallets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Wallet1?.setUser) {
|
|
await Wallet1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Wallet2 = await Wallets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Wallet2?.setUser) {
|
|
await Wallet2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Wallet3 = await Wallets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Wallet3?.setUser) {
|
|
await Wallet3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await ProductivityTools.bulkCreate(ProductivityToolsData);
|
|
|
|
await Rewards.bulkCreate(RewardsData);
|
|
|
|
await Tasks.bulkCreate(TasksData);
|
|
|
|
await Transactions.bulkCreate(TransactionsData);
|
|
|
|
await Wallets.bulkCreate(WalletsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateTaskWithAssigned_user(),
|
|
|
|
await associateTransactionWithUser(),
|
|
|
|
await associateWalletWithUser(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('productivity_tools', null, {});
|
|
|
|
await queryInterface.bulkDelete('rewards', null, {});
|
|
|
|
await queryInterface.bulkDelete('tasks', null, {});
|
|
|
|
await queryInterface.bulkDelete('transactions', null, {});
|
|
|
|
await queryInterface.bulkDelete('wallets', null, {});
|
|
},
|
|
};
|