31617/backend/src/db/seeders/20231127130745-sample-data.js
2025-05-18 07:58:18 +00:00

1167 lines
24 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Attributes = db.attributes;
const Baskets = db.baskets;
const Codes = db.codes;
const DiscountCodes = db.discount_codes;
const KycSubmissions = db.kyc_submissions;
const OrderItems = db.order_items;
const Orders = db.orders;
const Products = db.products;
const TicketMessages = db.ticket_messages;
const Tickets = db.tickets;
const Variants = db.variants;
const WalletTransactions = db.wallet_transactions;
const AttributesData = [
{
name: 'Region',
},
{
name: 'Value',
},
{
name: 'Color',
},
{
name: 'Size',
},
];
const BasketsData = [
{
usd_amount: 500,
irr_cost: 4800000,
},
{
usd_amount: 1000,
irr_cost: 9600000,
},
{
usd_amount: 750,
irr_cost: 7200000,
},
{
usd_amount: 300,
irr_cost: 2880000,
},
];
const CodesData = [
{
// type code here for "relation_one" field
code: 'STEAM-1234-5678-9012',
usd_value: 10,
// type code here for "relation_one" field
used_at: new Date(Date.now()),
},
{
// type code here for "relation_one" field
code: 'STEAM-2345-6789-0123',
usd_value: 50,
// type code here for "relation_one" field
used_at: new Date('2023-10-06T15:00:00Z'),
},
{
// type code here for "relation_one" field
code: 'PUBG-3456-7890-1234',
usd_value: 5,
// type code here for "relation_one" field
used_at: new Date(Date.now()),
},
{
// type code here for "relation_one" field
code: 'PUBG-4567-8901-2345',
usd_value: 15,
// type code here for "relation_one" field
used_at: new Date('2023-10-07T16:00:00Z'),
},
];
const DiscountCodesData = [
{
code: 'WELCOME10',
type: 'percentage',
value: 10,
max_uses: 100,
expires_at: new Date('2023-12-31T23:59:59Z'),
},
{
code: 'FALLSALE',
type: 'fixed',
value: 50000,
max_uses: 50,
expires_at: new Date('2023-11-30T23:59:59Z'),
},
{
code: 'NEWUSER',
type: 'fixed',
value: 15,
max_uses: 200,
expires_at: new Date('2024-01-31T23:59:59Z'),
},
{
code: 'BLACKFRIDAY',
type: 'percentage',
value: 100000,
max_uses: 30,
expires_at: new Date('2023-11-25T23:59:59Z'),
},
];
const KycSubmissionsData = [
{
// type code here for "relation_one" field
national_id: '1234567890',
// type code here for "files" field
// type code here for "files" field
status: 'Pending',
feedback: 'Verified successfully.',
},
{
// type code here for "relation_one" field
national_id: '0987654321',
// type code here for "files" field
// type code here for "files" field
status: 'Approved',
feedback: 'Awaiting verification.',
},
{
// type code here for "relation_one" field
national_id: '1122334455',
// type code here for "files" field
// type code here for "files" field
status: 'Pending',
feedback: 'Image not clear.',
},
{
// type code here for "relation_one" field
national_id: '2233445566',
// type code here for "files" field
// type code here for "files" field
status: 'Pending',
feedback: 'Verified successfully.',
},
];
const OrderItemsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
quantity: 1,
price_irr: 1500000,
activation_by_zipodo: true,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
quantity: 2,
price_irr: 500000,
activation_by_zipodo: true,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
quantity: 1,
price_irr: 250000,
activation_by_zipodo: true,
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
quantity: 3,
price_irr: 2000000,
activation_by_zipodo: true,
},
];
const OrdersData = [
{
// type code here for "relation_one" field
total_irr: 1500000,
status: 'Pending',
paid_at: new Date('2023-10-08T17:00:00Z'),
},
{
// type code here for "relation_one" field
total_irr: 500000,
status: 'Pending',
paid_at: new Date(Date.now()),
},
{
// type code here for "relation_one" field
total_irr: 250000,
status: 'Paid',
paid_at: new Date(Date.now()),
},
{
// type code here for "relation_one" field
total_irr: 2000000,
status: 'Paid',
paid_at: new Date('2023-10-09T18:00:00Z'),
},
];
const ProductsData = [
{
type: 'single',
title: 'Apple Gift Card',
description: 'Apple gift card for App Store purchases.',
// type code here for "images" field
price_type: 'dynamic',
price_irr: 70.55,
},
{
type: 'variable',
title: 'Steam Gift Card',
description: 'Steam gift card for game purchases.',
// type code here for "images" field
price_type: 'dynamic',
price_irr: 500000,
},
{
type: 'variable',
title: 'PlayStation Gift Card',
description: 'PlayStation gift card for PSN purchases.',
// type code here for "images" field
price_type: 'manual',
price_irr: 31.28,
},
{
type: 'variable',
title: 'PUBG UC',
description: 'PUBG UC for in-game purchases.',
// type code here for "images" field
price_type: 'manual',
price_irr: 300000,
},
];
const TicketMessagesData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
message: "I haven't received my order yet.",
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
message: 'Payment was deducted but order not confirmed.',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
message: 'My KYC is still pending.',
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
message: 'Is the product available in Turkey?',
},
];
const TicketsData = [
{
// type code here for "relation_one" field
subject: 'Order not received',
status: 'Closed',
},
{
// type code here for "relation_one" field
subject: 'Payment issue',
status: 'Open',
},
{
// type code here for "relation_one" field
subject: 'KYC verification',
status: 'Open',
},
{
// type code here for "relation_one" field
subject: 'Product inquiry',
status: 'Open',
},
];
const VariantsData = [
{
// type code here for "relation_one" field
attribute_values: '{Region:USA,Value:10 USD}',
price_usd: 10,
price_irr: 17.45,
},
{
// type code here for "relation_one" field
attribute_values: '{Region:Turkey,Value:50 USD}',
price_usd: 50,
price_irr: 22.62,
},
{
// type code here for "relation_one" field
attribute_values: '{Region:Global,Value:600 UC}',
price_usd: 5,
price_irr: 150000,
},
{
// type code here for "relation_one" field
attribute_values: '{Region:Global,Value:1800 UC}',
price_usd: 15,
price_irr: 450000,
},
];
const WalletTransactionsData = [
{
// type code here for "relation_one" field
amount: 500000,
type: 'refunded',
},
{
// type code here for "relation_one" field
amount: 250000,
type: 'payment',
},
{
// type code here for "relation_one" field
amount: 100000,
type: 'refunded',
},
{
// type code here for "relation_one" field
amount: 750000,
type: 'refunded',
},
];
// Similar logic for "relation_many"
async function associateCodeWithVariant() {
const relatedVariant0 = await Variants.findOne({
offset: Math.floor(Math.random() * (await Variants.count())),
});
const Code0 = await Codes.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Code0?.setVariant) {
await Code0.setVariant(relatedVariant0);
}
const relatedVariant1 = await Variants.findOne({
offset: Math.floor(Math.random() * (await Variants.count())),
});
const Code1 = await Codes.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Code1?.setVariant) {
await Code1.setVariant(relatedVariant1);
}
const relatedVariant2 = await Variants.findOne({
offset: Math.floor(Math.random() * (await Variants.count())),
});
const Code2 = await Codes.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Code2?.setVariant) {
await Code2.setVariant(relatedVariant2);
}
const relatedVariant3 = await Variants.findOne({
offset: Math.floor(Math.random() * (await Variants.count())),
});
const Code3 = await Codes.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Code3?.setVariant) {
await Code3.setVariant(relatedVariant3);
}
}
async function associateCodeWithBasket() {
const relatedBasket0 = await Baskets.findOne({
offset: Math.floor(Math.random() * (await Baskets.count())),
});
const Code0 = await Codes.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Code0?.setBasket) {
await Code0.setBasket(relatedBasket0);
}
const relatedBasket1 = await Baskets.findOne({
offset: Math.floor(Math.random() * (await Baskets.count())),
});
const Code1 = await Codes.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Code1?.setBasket) {
await Code1.setBasket(relatedBasket1);
}
const relatedBasket2 = await Baskets.findOne({
offset: Math.floor(Math.random() * (await Baskets.count())),
});
const Code2 = await Codes.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Code2?.setBasket) {
await Code2.setBasket(relatedBasket2);
}
const relatedBasket3 = await Baskets.findOne({
offset: Math.floor(Math.random() * (await Baskets.count())),
});
const Code3 = await Codes.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Code3?.setBasket) {
await Code3.setBasket(relatedBasket3);
}
}
async function associateKycSubmissionWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const KycSubmission0 = await KycSubmissions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (KycSubmission0?.setUser) {
await KycSubmission0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const KycSubmission1 = await KycSubmissions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (KycSubmission1?.setUser) {
await KycSubmission1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const KycSubmission2 = await KycSubmissions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (KycSubmission2?.setUser) {
await KycSubmission2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const KycSubmission3 = await KycSubmissions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (KycSubmission3?.setUser) {
await KycSubmission3.setUser(relatedUser3);
}
}
async function associateOrderItemWithOrder() {
const relatedOrder0 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const OrderItem0 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (OrderItem0?.setOrder) {
await OrderItem0.setOrder(relatedOrder0);
}
const relatedOrder1 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const OrderItem1 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (OrderItem1?.setOrder) {
await OrderItem1.setOrder(relatedOrder1);
}
const relatedOrder2 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const OrderItem2 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (OrderItem2?.setOrder) {
await OrderItem2.setOrder(relatedOrder2);
}
const relatedOrder3 = await Orders.findOne({
offset: Math.floor(Math.random() * (await Orders.count())),
});
const OrderItem3 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (OrderItem3?.setOrder) {
await OrderItem3.setOrder(relatedOrder3);
}
}
async function associateOrderItemWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem0 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (OrderItem0?.setProduct) {
await OrderItem0.setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem1 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (OrderItem1?.setProduct) {
await OrderItem1.setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem2 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (OrderItem2?.setProduct) {
await OrderItem2.setProduct(relatedProduct2);
}
const relatedProduct3 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const OrderItem3 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (OrderItem3?.setProduct) {
await OrderItem3.setProduct(relatedProduct3);
}
}
async function associateOrderItemWithVariant() {
const relatedVariant0 = await Variants.findOne({
offset: Math.floor(Math.random() * (await Variants.count())),
});
const OrderItem0 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (OrderItem0?.setVariant) {
await OrderItem0.setVariant(relatedVariant0);
}
const relatedVariant1 = await Variants.findOne({
offset: Math.floor(Math.random() * (await Variants.count())),
});
const OrderItem1 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (OrderItem1?.setVariant) {
await OrderItem1.setVariant(relatedVariant1);
}
const relatedVariant2 = await Variants.findOne({
offset: Math.floor(Math.random() * (await Variants.count())),
});
const OrderItem2 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (OrderItem2?.setVariant) {
await OrderItem2.setVariant(relatedVariant2);
}
const relatedVariant3 = await Variants.findOne({
offset: Math.floor(Math.random() * (await Variants.count())),
});
const OrderItem3 = await OrderItems.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (OrderItem3?.setVariant) {
await OrderItem3.setVariant(relatedVariant3);
}
}
async function associateOrderWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Order0 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Order0?.setUser) {
await Order0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Order1 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Order1?.setUser) {
await Order1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Order2 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Order2?.setUser) {
await Order2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Order3 = await Orders.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Order3?.setUser) {
await Order3.setUser(relatedUser3);
}
}
async function associateTicketMessageWithTicket() {
const relatedTicket0 = await Tickets.findOne({
offset: Math.floor(Math.random() * (await Tickets.count())),
});
const TicketMessage0 = await TicketMessages.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (TicketMessage0?.setTicket) {
await TicketMessage0.setTicket(relatedTicket0);
}
const relatedTicket1 = await Tickets.findOne({
offset: Math.floor(Math.random() * (await Tickets.count())),
});
const TicketMessage1 = await TicketMessages.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (TicketMessage1?.setTicket) {
await TicketMessage1.setTicket(relatedTicket1);
}
const relatedTicket2 = await Tickets.findOne({
offset: Math.floor(Math.random() * (await Tickets.count())),
});
const TicketMessage2 = await TicketMessages.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (TicketMessage2?.setTicket) {
await TicketMessage2.setTicket(relatedTicket2);
}
const relatedTicket3 = await Tickets.findOne({
offset: Math.floor(Math.random() * (await Tickets.count())),
});
const TicketMessage3 = await TicketMessages.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (TicketMessage3?.setTicket) {
await TicketMessage3.setTicket(relatedTicket3);
}
}
async function associateTicketMessageWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const TicketMessage0 = await TicketMessages.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (TicketMessage0?.setUser) {
await TicketMessage0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const TicketMessage1 = await TicketMessages.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (TicketMessage1?.setUser) {
await TicketMessage1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const TicketMessage2 = await TicketMessages.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (TicketMessage2?.setUser) {
await TicketMessage2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const TicketMessage3 = await TicketMessages.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (TicketMessage3?.setUser) {
await TicketMessage3.setUser(relatedUser3);
}
}
async function associateTicketWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Ticket0 = await Tickets.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Ticket0?.setUser) {
await Ticket0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Ticket1 = await Tickets.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Ticket1?.setUser) {
await Ticket1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Ticket2 = await Tickets.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Ticket2?.setUser) {
await Ticket2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Ticket3 = await Tickets.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Ticket3?.setUser) {
await Ticket3.setUser(relatedUser3);
}
}
async function associateVariantWithProduct() {
const relatedProduct0 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const Variant0 = await Variants.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Variant0?.setProduct) {
await Variant0.setProduct(relatedProduct0);
}
const relatedProduct1 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const Variant1 = await Variants.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Variant1?.setProduct) {
await Variant1.setProduct(relatedProduct1);
}
const relatedProduct2 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const Variant2 = await Variants.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Variant2?.setProduct) {
await Variant2.setProduct(relatedProduct2);
}
const relatedProduct3 = await Products.findOne({
offset: Math.floor(Math.random() * (await Products.count())),
});
const Variant3 = await Variants.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Variant3?.setProduct) {
await Variant3.setProduct(relatedProduct3);
}
}
async function associateWalletTransactionWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WalletTransaction0 = await WalletTransactions.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (WalletTransaction0?.setUser) {
await WalletTransaction0.setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WalletTransaction1 = await WalletTransactions.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (WalletTransaction1?.setUser) {
await WalletTransaction1.setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WalletTransaction2 = await WalletTransactions.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (WalletTransaction2?.setUser) {
await WalletTransaction2.setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const WalletTransaction3 = await WalletTransactions.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (WalletTransaction3?.setUser) {
await WalletTransaction3.setUser(relatedUser3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Attributes.bulkCreate(AttributesData);
await Baskets.bulkCreate(BasketsData);
await Codes.bulkCreate(CodesData);
await DiscountCodes.bulkCreate(DiscountCodesData);
await KycSubmissions.bulkCreate(KycSubmissionsData);
await OrderItems.bulkCreate(OrderItemsData);
await Orders.bulkCreate(OrdersData);
await Products.bulkCreate(ProductsData);
await TicketMessages.bulkCreate(TicketMessagesData);
await Tickets.bulkCreate(TicketsData);
await Variants.bulkCreate(VariantsData);
await WalletTransactions.bulkCreate(WalletTransactionsData);
await Promise.all([
// Similar logic for "relation_many"
await associateCodeWithVariant(),
await associateCodeWithBasket(),
await associateKycSubmissionWithUser(),
await associateOrderItemWithOrder(),
await associateOrderItemWithProduct(),
await associateOrderItemWithVariant(),
await associateOrderWithUser(),
await associateTicketMessageWithTicket(),
await associateTicketMessageWithUser(),
await associateTicketWithUser(),
await associateVariantWithProduct(),
await associateWalletTransactionWithUser(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('attributes', null, {});
await queryInterface.bulkDelete('baskets', null, {});
await queryInterface.bulkDelete('codes', null, {});
await queryInterface.bulkDelete('discount_codes', null, {});
await queryInterface.bulkDelete('kyc_submissions', null, {});
await queryInterface.bulkDelete('order_items', null, {});
await queryInterface.bulkDelete('orders', null, {});
await queryInterface.bulkDelete('products', null, {});
await queryInterface.bulkDelete('ticket_messages', null, {});
await queryInterface.bulkDelete('tickets', null, {});
await queryInterface.bulkDelete('variants', null, {});
await queryInterface.bulkDelete('wallet_transactions', null, {});
},
};