30026/backend/src/db/seeders/20231127130745-sample-data.js
2025-03-19 07:07:42 +00:00

337 lines
7.1 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Notifications = db.notifications;
const TaxReports = db.tax_reports;
const Transactions = db.transactions;
const Wallets = db.wallets;
const NotificationsData = [
{
message: 'You have 3 transactions with missing cost basis',
sent_date: new Date('2023-09-01T10:00:00Z'),
is_read: false,
// type code here for "relation_one" field
},
{
message: "You've reached your 100-transaction free plan limit",
sent_date: new Date('2023-09-10T11:00:00Z'),
is_read: true,
// type code here for "relation_one" field
},
{
message: 'Tax deadline approaching — Generate your Form 8949',
sent_date: new Date('2023-09-15T12:00:00Z'),
is_read: true,
// type code here for "relation_one" field
},
];
const TaxReportsData = [
{
report_type: 'Form 8949',
generated_date: new Date('2023-06-01T10:00:00Z'),
// type code here for "files" field
// type code here for "relation_one" field
},
{
report_type: 'Schedule D',
generated_date: new Date('2023-06-15T11:00:00Z'),
// type code here for "files" field
// type code here for "relation_one" field
},
{
report_type: 'Schedule 1',
generated_date: new Date('2023-07-01T12:00:00Z'),
// type code here for "files" field
// type code here for "relation_one" field
},
];
const TransactionsData = [
{
asset: 'BTC',
quantity: 0.5,
price: 30000,
fees: 10,
transaction_date: new Date('2023-01-15T10:00:00Z'),
category: 'Mining',
// type code here for "relation_one" field
},
{
asset: 'ETH',
quantity: 2,
price: 1500,
fees: 5,
transaction_date: new Date('2023-02-20T12:00:00Z'),
category: 'Staking',
// type code here for "relation_one" field
},
{
asset: 'ADA',
quantity: 1000,
price: 1.2,
fees: 2,
transaction_date: new Date('2023-03-10T14:30:00Z'),
category: 'Buy',
// type code here for "relation_one" field
},
];
const WalletsData = [
{
name: 'Binance Wallet',
type: 'Exchange',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'Coinbase Wallet',
type: 'Exchange',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
{
name: 'MetaMask Wallet',
type: 'Hardware',
// type code here for "relation_many" field
// type code here for "relation_one" field
},
];
// Similar logic for "relation_many"
async function associateNotificationWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Notification0 = await Notifications.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Notification0?.setUser) {
await Notification0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Notification1 = await Notifications.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Notification1?.setUser) {
await Notification1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Notification2 = await Notifications.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Notification2?.setUser) {
await Notification2.setUser(relatedUser2);
}
}
async function associateTaxReportWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const TaxReport0 = await TaxReports.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (TaxReport0?.setUser) {
await TaxReport0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const TaxReport1 = await TaxReports.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (TaxReport1?.setUser) {
await TaxReport1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const TaxReport2 = await TaxReports.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (TaxReport2?.setUser) {
await TaxReport2.setUser(relatedUser2);
}
}
async function associateTransactionWithWallet() {
const relatedWallet0 = await Wallets.findOne({
offset: Math.floor(Math.random() * (await Wallets.count())),
});
const Transaction0 = await Transactions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Transaction0?.setWallet) {
await Transaction0.setWallet(relatedWallet0);
}
const relatedWallet1 = await Wallets.findOne({
offset: Math.floor(Math.random() * (await Wallets.count())),
});
const Transaction1 = await Transactions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Transaction1?.setWallet) {
await Transaction1.setWallet(relatedWallet1);
}
const relatedWallet2 = await Wallets.findOne({
offset: Math.floor(Math.random() * (await Wallets.count())),
});
const Transaction2 = await Transactions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Transaction2?.setWallet) {
await Transaction2.setWallet(relatedWallet2);
}
}
// Similar logic for "relation_many"
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);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Notifications.bulkCreate(NotificationsData);
await TaxReports.bulkCreate(TaxReportsData);
await Transactions.bulkCreate(TransactionsData);
await Wallets.bulkCreate(WalletsData);
await Promise.all([
// Similar logic for "relation_many"
await associateNotificationWithUser(),
await associateTaxReportWithUser(),
await associateTransactionWithWallet(),
// Similar logic for "relation_many"
await associateWalletWithUser(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('notifications', null, {});
await queryInterface.bulkDelete('tax_reports', null, {});
await queryInterface.bulkDelete('transactions', null, {});
await queryInterface.bulkDelete('wallets', null, {});
},
};