497 lines
12 KiB
JavaScript
497 lines
12 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const ExcelLayoutTemplates = db.excel_layout_templates;
|
|
|
|
const Mailings = db.mailings;
|
|
|
|
const ScreenshotConfigurations = db.screenshot_configurations;
|
|
|
|
const UserFilters = db.user_filters;
|
|
|
|
const ExcelLayoutTemplatesData = [
|
|
{
|
|
template_name: 'Standard Report',
|
|
|
|
description: 'Basic layout for standard reports',
|
|
|
|
version_date: new Date('2023-10-01T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
template_name: 'Financial Overview',
|
|
|
|
description: 'Layout for financial summaries',
|
|
|
|
version_date: new Date('2023-10-05T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
template_name: 'Sales Dashboard',
|
|
|
|
description: 'Sales data presentation layout',
|
|
|
|
version_date: new Date('2023-10-10T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
template_name: 'Performance Metrics',
|
|
|
|
description: 'Template for performance metrics',
|
|
|
|
version_date: new Date('2023-10-15T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
template_name: 'Custom Template',
|
|
|
|
description: 'User-defined custom layout',
|
|
|
|
version_date: new Date('2023-10-20T00:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const MailingsData = [
|
|
{
|
|
name: 'Weekly Sales Report',
|
|
|
|
scheduled_time: new Date('2023-11-01T09:00:00Z'),
|
|
|
|
completed_time: new Date('2023-11-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
is_recurring: true,
|
|
},
|
|
|
|
{
|
|
name: 'Monthly Performance Review',
|
|
|
|
scheduled_time: new Date('2023-11-05T14:00:00Z'),
|
|
|
|
completed_time: new Date('2023-11-05T15:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
is_recurring: true,
|
|
},
|
|
|
|
{
|
|
name: 'Quarterly Financial Summary',
|
|
|
|
scheduled_time: new Date('2023-11-10T11:00:00Z'),
|
|
|
|
completed_time: new Date('2023-11-10T12:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
is_recurring: false,
|
|
},
|
|
|
|
{
|
|
name: 'Annual Report',
|
|
|
|
scheduled_time: new Date('2023-12-01T10:00:00Z'),
|
|
|
|
completed_time: new Date('2023-12-01T11:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
is_recurring: true,
|
|
},
|
|
|
|
{
|
|
name: 'Daily Metrics Update',
|
|
|
|
scheduled_time: new Date('2023-11-02T08:00:00Z'),
|
|
|
|
completed_time: new Date('2023-11-02T09:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
is_recurring: true,
|
|
},
|
|
];
|
|
|
|
const ScreenshotConfigurationsData = [
|
|
{
|
|
config_name: 'Sales Filter',
|
|
|
|
filters: 'region: North America',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
config_name: 'Finance Filter',
|
|
|
|
filters: 'department: Finance',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
config_name: 'Marketing Filter',
|
|
|
|
filters: 'campaign: Q4 Launch',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
config_name: 'HR Filter',
|
|
|
|
filters: 'role: Manager',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
config_name: 'IT Filter',
|
|
|
|
filters: 'system: Internal',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const UserFiltersData = [
|
|
{
|
|
filter_name: 'Region Filter',
|
|
|
|
filter_value: 'North America',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
filter_name: 'Department Filter',
|
|
|
|
filter_value: 'Finance',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
filter_name: 'Campaign Filter',
|
|
|
|
filter_value: 'Q4 Launch',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
filter_name: 'Role Filter',
|
|
|
|
filter_value: 'Manager',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
filter_name: 'System Filter',
|
|
|
|
filter_value: 'Internal',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateMailingWithLayout_template() {
|
|
const relatedLayout_template0 = await ExcelLayoutTemplates.findOne({
|
|
offset: Math.floor(Math.random() * (await ExcelLayoutTemplates.count())),
|
|
});
|
|
const Mailing0 = await Mailings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Mailing0?.setLayout_template) {
|
|
await Mailing0.setLayout_template(relatedLayout_template0);
|
|
}
|
|
|
|
const relatedLayout_template1 = await ExcelLayoutTemplates.findOne({
|
|
offset: Math.floor(Math.random() * (await ExcelLayoutTemplates.count())),
|
|
});
|
|
const Mailing1 = await Mailings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Mailing1?.setLayout_template) {
|
|
await Mailing1.setLayout_template(relatedLayout_template1);
|
|
}
|
|
|
|
const relatedLayout_template2 = await ExcelLayoutTemplates.findOne({
|
|
offset: Math.floor(Math.random() * (await ExcelLayoutTemplates.count())),
|
|
});
|
|
const Mailing2 = await Mailings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Mailing2?.setLayout_template) {
|
|
await Mailing2.setLayout_template(relatedLayout_template2);
|
|
}
|
|
|
|
const relatedLayout_template3 = await ExcelLayoutTemplates.findOne({
|
|
offset: Math.floor(Math.random() * (await ExcelLayoutTemplates.count())),
|
|
});
|
|
const Mailing3 = await Mailings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Mailing3?.setLayout_template) {
|
|
await Mailing3.setLayout_template(relatedLayout_template3);
|
|
}
|
|
|
|
const relatedLayout_template4 = await ExcelLayoutTemplates.findOne({
|
|
offset: Math.floor(Math.random() * (await ExcelLayoutTemplates.count())),
|
|
});
|
|
const Mailing4 = await Mailings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Mailing4?.setLayout_template) {
|
|
await Mailing4.setLayout_template(relatedLayout_template4);
|
|
}
|
|
}
|
|
|
|
async function associateMailingWithScreenshot_config() {
|
|
const relatedScreenshot_config0 = await ScreenshotConfigurations.findOne({
|
|
offset: Math.floor(
|
|
Math.random() * (await ScreenshotConfigurations.count()),
|
|
),
|
|
});
|
|
const Mailing0 = await Mailings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Mailing0?.setScreenshot_config) {
|
|
await Mailing0.setScreenshot_config(relatedScreenshot_config0);
|
|
}
|
|
|
|
const relatedScreenshot_config1 = await ScreenshotConfigurations.findOne({
|
|
offset: Math.floor(
|
|
Math.random() * (await ScreenshotConfigurations.count()),
|
|
),
|
|
});
|
|
const Mailing1 = await Mailings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Mailing1?.setScreenshot_config) {
|
|
await Mailing1.setScreenshot_config(relatedScreenshot_config1);
|
|
}
|
|
|
|
const relatedScreenshot_config2 = await ScreenshotConfigurations.findOne({
|
|
offset: Math.floor(
|
|
Math.random() * (await ScreenshotConfigurations.count()),
|
|
),
|
|
});
|
|
const Mailing2 = await Mailings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Mailing2?.setScreenshot_config) {
|
|
await Mailing2.setScreenshot_config(relatedScreenshot_config2);
|
|
}
|
|
|
|
const relatedScreenshot_config3 = await ScreenshotConfigurations.findOne({
|
|
offset: Math.floor(
|
|
Math.random() * (await ScreenshotConfigurations.count()),
|
|
),
|
|
});
|
|
const Mailing3 = await Mailings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Mailing3?.setScreenshot_config) {
|
|
await Mailing3.setScreenshot_config(relatedScreenshot_config3);
|
|
}
|
|
|
|
const relatedScreenshot_config4 = await ScreenshotConfigurations.findOne({
|
|
offset: Math.floor(
|
|
Math.random() * (await ScreenshotConfigurations.count()),
|
|
),
|
|
});
|
|
const Mailing4 = await Mailings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Mailing4?.setScreenshot_config) {
|
|
await Mailing4.setScreenshot_config(relatedScreenshot_config4);
|
|
}
|
|
}
|
|
|
|
async function associateScreenshotConfigurationWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ScreenshotConfiguration0 = await ScreenshotConfigurations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (ScreenshotConfiguration0?.setUser) {
|
|
await ScreenshotConfiguration0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ScreenshotConfiguration1 = await ScreenshotConfigurations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (ScreenshotConfiguration1?.setUser) {
|
|
await ScreenshotConfiguration1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ScreenshotConfiguration2 = await ScreenshotConfigurations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (ScreenshotConfiguration2?.setUser) {
|
|
await ScreenshotConfiguration2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ScreenshotConfiguration3 = await ScreenshotConfigurations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (ScreenshotConfiguration3?.setUser) {
|
|
await ScreenshotConfiguration3.setUser(relatedUser3);
|
|
}
|
|
|
|
const relatedUser4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ScreenshotConfiguration4 = await ScreenshotConfigurations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (ScreenshotConfiguration4?.setUser) {
|
|
await ScreenshotConfiguration4.setUser(relatedUser4);
|
|
}
|
|
}
|
|
|
|
async function associateUserFilterWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserFilter0 = await UserFilters.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (UserFilter0?.setUser) {
|
|
await UserFilter0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserFilter1 = await UserFilters.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (UserFilter1?.setUser) {
|
|
await UserFilter1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserFilter2 = await UserFilters.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (UserFilter2?.setUser) {
|
|
await UserFilter2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserFilter3 = await UserFilters.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (UserFilter3?.setUser) {
|
|
await UserFilter3.setUser(relatedUser3);
|
|
}
|
|
|
|
const relatedUser4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const UserFilter4 = await UserFilters.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (UserFilter4?.setUser) {
|
|
await UserFilter4.setUser(relatedUser4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await ExcelLayoutTemplates.bulkCreate(ExcelLayoutTemplatesData);
|
|
|
|
await Mailings.bulkCreate(MailingsData);
|
|
|
|
await ScreenshotConfigurations.bulkCreate(ScreenshotConfigurationsData);
|
|
|
|
await UserFilters.bulkCreate(UserFiltersData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateMailingWithLayout_template(),
|
|
|
|
await associateMailingWithScreenshot_config(),
|
|
|
|
await associateScreenshotConfigurationWithUser(),
|
|
|
|
await associateUserFilterWithUser(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('excel_layout_templates', null, {});
|
|
|
|
await queryInterface.bulkDelete('mailings', null, {});
|
|
|
|
await queryInterface.bulkDelete('screenshot_configurations', null, {});
|
|
|
|
await queryInterface.bulkDelete('user_filters', null, {});
|
|
},
|
|
};
|