31504/backend/src/db/seeders/20231127130745-sample-data.js
2025-05-14 01:39:22 +00:00

433 lines
9.9 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const AutomaticReplies = db.automatic_replies;
const FacebookGroups = db.facebook_groups;
const Posts = db.posts;
const ReplyLogs = db.reply_logs;
const AutomaticRepliesData = [
{
reply_template: "Thank you for your interest! We'll get back to you soon.",
status: 'active',
// type code here for "relation_one" field
},
{
reply_template: 'Join our mailing list for updates.',
status: 'paused',
// type code here for "relation_one" field
},
{
reply_template: 'We appreciate your feedback!',
status: 'paused',
// type code here for "relation_one" field
},
{
reply_template: 'Stay tuned for more tips!',
status: 'paused',
// type code here for "relation_one" field
},
{
reply_template: "Let's make a difference together!",
status: 'active',
// type code here for "relation_one" field
},
];
const FacebookGroupsData = [
{
group_name: 'Marketing Enthusiasts',
group_id: '1234567890',
},
{
group_name: 'Tech Innovators',
group_id: '0987654321',
},
{
group_name: 'Startup Founders',
group_id: '1122334455',
},
{
group_name: 'Digital Nomads',
group_id: '5566778899',
},
{
group_name: 'Eco Warriors',
group_id: '6677889900',
},
];
const PostsData = [
{
content: 'Check out our latest product launch!',
posted_at: new Date('2023-10-01T10:00:00Z'),
// type code here for "relation_one" field
},
{
content: 'Join our webinar on AI trends.',
posted_at: new Date('2023-10-02T11:30:00Z'),
// type code here for "relation_one" field
},
{
content: 'Looking for co-founders for a new venture.',
posted_at: new Date('2023-10-03T09:15:00Z'),
// type code here for "relation_one" field
},
{
content: 'Tips for remote work productivity.',
posted_at: new Date('2023-10-04T14:45:00Z'),
// type code here for "relation_one" field
},
{
content: 'Sustainable living practices.',
posted_at: new Date('2023-10-05T16:20:00Z'),
// type code here for "relation_one" field
},
];
const ReplyLogsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
replied_at: new Date('2023-10-01T10:05:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
replied_at: new Date('2023-10-02T11:35:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
replied_at: new Date('2023-10-03T09:20:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
replied_at: new Date('2023-10-04T14:50:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
replied_at: new Date('2023-10-05T16:25:00Z'),
},
];
// Similar logic for "relation_many"
async function associateAutomaticReplyWithGroup() {
const relatedGroup0 = await FacebookGroups.findOne({
offset: Math.floor(Math.random() * (await FacebookGroups.count())),
});
const AutomaticReply0 = await AutomaticReplies.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (AutomaticReply0?.setGroup) {
await AutomaticReply0.setGroup(relatedGroup0);
}
const relatedGroup1 = await FacebookGroups.findOne({
offset: Math.floor(Math.random() * (await FacebookGroups.count())),
});
const AutomaticReply1 = await AutomaticReplies.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (AutomaticReply1?.setGroup) {
await AutomaticReply1.setGroup(relatedGroup1);
}
const relatedGroup2 = await FacebookGroups.findOne({
offset: Math.floor(Math.random() * (await FacebookGroups.count())),
});
const AutomaticReply2 = await AutomaticReplies.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (AutomaticReply2?.setGroup) {
await AutomaticReply2.setGroup(relatedGroup2);
}
const relatedGroup3 = await FacebookGroups.findOne({
offset: Math.floor(Math.random() * (await FacebookGroups.count())),
});
const AutomaticReply3 = await AutomaticReplies.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (AutomaticReply3?.setGroup) {
await AutomaticReply3.setGroup(relatedGroup3);
}
const relatedGroup4 = await FacebookGroups.findOne({
offset: Math.floor(Math.random() * (await FacebookGroups.count())),
});
const AutomaticReply4 = await AutomaticReplies.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (AutomaticReply4?.setGroup) {
await AutomaticReply4.setGroup(relatedGroup4);
}
}
async function associatePostWithGroup() {
const relatedGroup0 = await FacebookGroups.findOne({
offset: Math.floor(Math.random() * (await FacebookGroups.count())),
});
const Post0 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Post0?.setGroup) {
await Post0.setGroup(relatedGroup0);
}
const relatedGroup1 = await FacebookGroups.findOne({
offset: Math.floor(Math.random() * (await FacebookGroups.count())),
});
const Post1 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Post1?.setGroup) {
await Post1.setGroup(relatedGroup1);
}
const relatedGroup2 = await FacebookGroups.findOne({
offset: Math.floor(Math.random() * (await FacebookGroups.count())),
});
const Post2 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Post2?.setGroup) {
await Post2.setGroup(relatedGroup2);
}
const relatedGroup3 = await FacebookGroups.findOne({
offset: Math.floor(Math.random() * (await FacebookGroups.count())),
});
const Post3 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Post3?.setGroup) {
await Post3.setGroup(relatedGroup3);
}
const relatedGroup4 = await FacebookGroups.findOne({
offset: Math.floor(Math.random() * (await FacebookGroups.count())),
});
const Post4 = await Posts.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Post4?.setGroup) {
await Post4.setGroup(relatedGroup4);
}
}
async function associateReplyLogWithPost() {
const relatedPost0 = await Posts.findOne({
offset: Math.floor(Math.random() * (await Posts.count())),
});
const ReplyLog0 = await ReplyLogs.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (ReplyLog0?.setPost) {
await ReplyLog0.setPost(relatedPost0);
}
const relatedPost1 = await Posts.findOne({
offset: Math.floor(Math.random() * (await Posts.count())),
});
const ReplyLog1 = await ReplyLogs.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (ReplyLog1?.setPost) {
await ReplyLog1.setPost(relatedPost1);
}
const relatedPost2 = await Posts.findOne({
offset: Math.floor(Math.random() * (await Posts.count())),
});
const ReplyLog2 = await ReplyLogs.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (ReplyLog2?.setPost) {
await ReplyLog2.setPost(relatedPost2);
}
const relatedPost3 = await Posts.findOne({
offset: Math.floor(Math.random() * (await Posts.count())),
});
const ReplyLog3 = await ReplyLogs.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (ReplyLog3?.setPost) {
await ReplyLog3.setPost(relatedPost3);
}
const relatedPost4 = await Posts.findOne({
offset: Math.floor(Math.random() * (await Posts.count())),
});
const ReplyLog4 = await ReplyLogs.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (ReplyLog4?.setPost) {
await ReplyLog4.setPost(relatedPost4);
}
}
async function associateReplyLogWithReply() {
const relatedReply0 = await AutomaticReplies.findOne({
offset: Math.floor(Math.random() * (await AutomaticReplies.count())),
});
const ReplyLog0 = await ReplyLogs.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (ReplyLog0?.setReply) {
await ReplyLog0.setReply(relatedReply0);
}
const relatedReply1 = await AutomaticReplies.findOne({
offset: Math.floor(Math.random() * (await AutomaticReplies.count())),
});
const ReplyLog1 = await ReplyLogs.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (ReplyLog1?.setReply) {
await ReplyLog1.setReply(relatedReply1);
}
const relatedReply2 = await AutomaticReplies.findOne({
offset: Math.floor(Math.random() * (await AutomaticReplies.count())),
});
const ReplyLog2 = await ReplyLogs.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (ReplyLog2?.setReply) {
await ReplyLog2.setReply(relatedReply2);
}
const relatedReply3 = await AutomaticReplies.findOne({
offset: Math.floor(Math.random() * (await AutomaticReplies.count())),
});
const ReplyLog3 = await ReplyLogs.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (ReplyLog3?.setReply) {
await ReplyLog3.setReply(relatedReply3);
}
const relatedReply4 = await AutomaticReplies.findOne({
offset: Math.floor(Math.random() * (await AutomaticReplies.count())),
});
const ReplyLog4 = await ReplyLogs.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (ReplyLog4?.setReply) {
await ReplyLog4.setReply(relatedReply4);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await AutomaticReplies.bulkCreate(AutomaticRepliesData);
await FacebookGroups.bulkCreate(FacebookGroupsData);
await Posts.bulkCreate(PostsData);
await ReplyLogs.bulkCreate(ReplyLogsData);
await Promise.all([
// Similar logic for "relation_many"
await associateAutomaticReplyWithGroup(),
await associatePostWithGroup(),
await associateReplyLogWithPost(),
await associateReplyLogWithReply(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('automatic_replies', null, {});
await queryInterface.bulkDelete('facebook_groups', null, {});
await queryInterface.bulkDelete('posts', null, {});
await queryInterface.bulkDelete('reply_logs', null, {});
},
};