38192-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-02-04 16:41:12 +00:00

1045 lines
17 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const ValentinePages = db.valentine_pages;
const ValentineInteractions = db.valentine_interactions;
const ValentinePagesData = [
{
"page_title": "Gvantsa Valentine Page",
"question_text": "Gvantsa, would you be my valentine?",
"yes_button_text": "Yes",
"no_button_text": "No",
"no_button_evasive": true,
"evasion_distance_px": 120,
"no_click_noop": true,
"yes_grow_per_click_pct": 8,
"is_published": true,
"published_at": new Date('2026-02-01T10:00:00Z'),
// type code here for "relation_one" field
},
{
"page_title": "Simple Valentine Prompt",
"question_text": "Would you be my valentine?",
"yes_button_text": "Absolutely",
"no_button_text": "Not today",
"no_button_evasive": true,
"evasion_distance_px": 140,
"no_click_noop": true,
"yes_grow_per_click_pct": 6,
"is_published": true,
"published_at": new Date('2026-02-01T09:30:00Z'),
// type code here for "relation_one" field
},
{
"page_title": "Cute Confirmation Page",
"question_text": "Will you be my valentine this year?",
"yes_button_text": "Yes please",
"no_button_text": "Nope",
"no_button_evasive": true,
"evasion_distance_px": 110,
"no_click_noop": true,
"yes_grow_per_click_pct": 10,
"is_published": false,
"published_at": new Date('2026-02-10T12:00:00Z'),
// type code here for "relation_one" field
},
{
"page_title": "Playful Evasive No Demo",
"question_text": "Be my valentine?",
"yes_button_text": "Yes!",
"no_button_text": "No",
"no_button_evasive": true,
"evasion_distance_px": 160,
"no_click_noop": true,
"yes_grow_per_click_pct": 5,
"is_published": true,
"published_at": new Date('2026-02-02T15:45:00Z'),
// type code here for "relation_one" field
},
];
const ValentineInteractionsData = [
{
// type code here for "relation_one" field
"interaction_type": "yes_click",
"session_key": "sess_9d2a4c10",
"ip_address": "203.0.113.10",
"user_agent": "Mozilla/5.0 Chrome/121.0",
"occurred_at": new Date('2026-02-03T18:22:10Z'),
"cursor_x": 512.4,
"cursor_y": 388.2,
"button_x": 640.0,
"button_y": 420.0,
"yes_scale_after_click": 1.0,
},
{
// type code here for "relation_one" field
"interaction_type": "yes_click",
"session_key": "sess_9d2a4c10",
"ip_address": "203.0.113.10",
"user_agent": "Mozilla/5.0 Chrome/121.0",
"occurred_at": new Date('2026-02-03T18:22:18Z'),
"cursor_x": 605.0,
"cursor_y": 418.0,
"button_x": 700.0,
"button_y": 420.0,
"yes_scale_after_click": 1.0,
},
{
// type code here for "relation_one" field
"interaction_type": "page_view",
"session_key": "sess_9d2a4c10",
"ip_address": "203.0.113.10",
"user_agent": "Mozilla/5.0 Chrome/121.0",
"occurred_at": new Date('2026-02-03T18:22:25Z'),
"cursor_x": 520.0,
"cursor_y": 430.0,
"button_x": 520.0,
"button_y": 430.0,
"yes_scale_after_click": 1.08,
},
{
// type code here for "relation_one" field
"interaction_type": "cursor_near_no",
"session_key": "sess_41c7b1f2",
"ip_address": "198.51.100.24",
"user_agent": "Mozilla/5.0 Safari/17.2",
"occurred_at": new Date('2026-02-02T12:05:12Z'),
"cursor_x": 480.0,
"cursor_y": 360.0,
"button_x": 610.0,
"button_y": 410.0,
"yes_scale_after_click": 1.0,
},
];
// Similar logic for "relation_many"
async function associateValentinePageWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ValentinePage0 = await ValentinePages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ValentinePage0?.setOwner)
{
await
ValentinePage0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ValentinePage1 = await ValentinePages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ValentinePage1?.setOwner)
{
await
ValentinePage1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ValentinePage2 = await ValentinePages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ValentinePage2?.setOwner)
{
await
ValentinePage2.
setOwner(relatedOwner2);
}
const relatedOwner3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ValentinePage3 = await ValentinePages.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ValentinePage3?.setOwner)
{
await
ValentinePage3.
setOwner(relatedOwner3);
}
}
async function associateValentineInteractionWithPage() {
const relatedPage0 = await ValentinePages.findOne({
offset: Math.floor(Math.random() * (await ValentinePages.count())),
});
const ValentineInteraction0 = await ValentineInteractions.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ValentineInteraction0?.setPage)
{
await
ValentineInteraction0.
setPage(relatedPage0);
}
const relatedPage1 = await ValentinePages.findOne({
offset: Math.floor(Math.random() * (await ValentinePages.count())),
});
const ValentineInteraction1 = await ValentineInteractions.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ValentineInteraction1?.setPage)
{
await
ValentineInteraction1.
setPage(relatedPage1);
}
const relatedPage2 = await ValentinePages.findOne({
offset: Math.floor(Math.random() * (await ValentinePages.count())),
});
const ValentineInteraction2 = await ValentineInteractions.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ValentineInteraction2?.setPage)
{
await
ValentineInteraction2.
setPage(relatedPage2);
}
const relatedPage3 = await ValentinePages.findOne({
offset: Math.floor(Math.random() * (await ValentinePages.count())),
});
const ValentineInteraction3 = await ValentineInteractions.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ValentineInteraction3?.setPage)
{
await
ValentineInteraction3.
setPage(relatedPage3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await ValentinePages.bulkCreate(ValentinePagesData);
await ValentineInteractions.bulkCreate(ValentineInteractionsData);
await Promise.all([
// Similar logic for "relation_many"
await associateValentinePageWithOwner(),
await associateValentineInteractionWithPage(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('valentine_pages', null, {});
await queryInterface.bulkDelete('valentine_interactions', null, {});
},
};