367 lines
8.9 KiB
JavaScript
367 lines
8.9 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Questions = db.questions;
|
|
|
|
const Replies = db.replies;
|
|
|
|
const QuestionsData = [
|
|
{
|
|
content: 'What does my birth chart say?',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
asked_at: new Date('2023-10-01T10:00:00Z'),
|
|
},
|
|
|
|
{
|
|
content: 'Will I find love this year?',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
asked_at: new Date('2023-10-02T11:30:00Z'),
|
|
},
|
|
|
|
{
|
|
content: 'How will my career progress?',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
asked_at: new Date('2023-10-03T12:45:00Z'),
|
|
},
|
|
|
|
{
|
|
content: 'What are my lucky numbers?',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
asked_at: new Date('2023-10-04T14:00:00Z'),
|
|
},
|
|
|
|
{
|
|
content: 'Should I invest in stocks?',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
asked_at: new Date('2023-10-05T15:15:00Z'),
|
|
},
|
|
];
|
|
|
|
const RepliesData = [
|
|
{
|
|
content: 'Your birth chart indicates a strong influence of Mars.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
replied_at: new Date('2023-10-01T11:00:00Z'),
|
|
},
|
|
|
|
{
|
|
content: 'Love is on the horizon, be open to new experiences.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
replied_at: new Date('2023-10-02T12:00:00Z'),
|
|
},
|
|
|
|
{
|
|
content: 'Your career will see significant growth in the coming months.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
replied_at: new Date('2023-10-03T13:00:00Z'),
|
|
},
|
|
|
|
{
|
|
content: 'Your lucky numbers are 3, 7, and 21.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
replied_at: new Date('2023-10-04T15:00:00Z'),
|
|
},
|
|
|
|
{
|
|
content: 'Consider diversifying your investments for better security.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
replied_at: new Date('2023-10-05T16:00:00Z'),
|
|
},
|
|
];
|
|
|
|
async function associateQuestionWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Question0 = await Questions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Question0?.setUser) {
|
|
await Question0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Question1 = await Questions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Question1?.setUser) {
|
|
await Question1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Question2 = await Questions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Question2?.setUser) {
|
|
await Question2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Question3 = await Questions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Question3?.setUser) {
|
|
await Question3.setUser(relatedUser3);
|
|
}
|
|
|
|
const relatedUser4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Question4 = await Questions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Question4?.setUser) {
|
|
await Question4.setUser(relatedUser4);
|
|
}
|
|
}
|
|
|
|
async function associateQuestionWithAstrologer() {
|
|
const relatedAstrologer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Question0 = await Questions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Question0?.setAstrologer) {
|
|
await Question0.setAstrologer(relatedAstrologer0);
|
|
}
|
|
|
|
const relatedAstrologer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Question1 = await Questions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Question1?.setAstrologer) {
|
|
await Question1.setAstrologer(relatedAstrologer1);
|
|
}
|
|
|
|
const relatedAstrologer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Question2 = await Questions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Question2?.setAstrologer) {
|
|
await Question2.setAstrologer(relatedAstrologer2);
|
|
}
|
|
|
|
const relatedAstrologer3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Question3 = await Questions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Question3?.setAstrologer) {
|
|
await Question3.setAstrologer(relatedAstrologer3);
|
|
}
|
|
|
|
const relatedAstrologer4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Question4 = await Questions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Question4?.setAstrologer) {
|
|
await Question4.setAstrologer(relatedAstrologer4);
|
|
}
|
|
}
|
|
|
|
async function associateReplyWithQuestion() {
|
|
const relatedQuestion0 = await Questions.findOne({
|
|
offset: Math.floor(Math.random() * (await Questions.count())),
|
|
});
|
|
const Reply0 = await Replies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Reply0?.setQuestion) {
|
|
await Reply0.setQuestion(relatedQuestion0);
|
|
}
|
|
|
|
const relatedQuestion1 = await Questions.findOne({
|
|
offset: Math.floor(Math.random() * (await Questions.count())),
|
|
});
|
|
const Reply1 = await Replies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Reply1?.setQuestion) {
|
|
await Reply1.setQuestion(relatedQuestion1);
|
|
}
|
|
|
|
const relatedQuestion2 = await Questions.findOne({
|
|
offset: Math.floor(Math.random() * (await Questions.count())),
|
|
});
|
|
const Reply2 = await Replies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Reply2?.setQuestion) {
|
|
await Reply2.setQuestion(relatedQuestion2);
|
|
}
|
|
|
|
const relatedQuestion3 = await Questions.findOne({
|
|
offset: Math.floor(Math.random() * (await Questions.count())),
|
|
});
|
|
const Reply3 = await Replies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Reply3?.setQuestion) {
|
|
await Reply3.setQuestion(relatedQuestion3);
|
|
}
|
|
|
|
const relatedQuestion4 = await Questions.findOne({
|
|
offset: Math.floor(Math.random() * (await Questions.count())),
|
|
});
|
|
const Reply4 = await Replies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Reply4?.setQuestion) {
|
|
await Reply4.setQuestion(relatedQuestion4);
|
|
}
|
|
}
|
|
|
|
async function associateReplyWithAstrologer() {
|
|
const relatedAstrologer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Reply0 = await Replies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Reply0?.setAstrologer) {
|
|
await Reply0.setAstrologer(relatedAstrologer0);
|
|
}
|
|
|
|
const relatedAstrologer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Reply1 = await Replies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Reply1?.setAstrologer) {
|
|
await Reply1.setAstrologer(relatedAstrologer1);
|
|
}
|
|
|
|
const relatedAstrologer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Reply2 = await Replies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Reply2?.setAstrologer) {
|
|
await Reply2.setAstrologer(relatedAstrologer2);
|
|
}
|
|
|
|
const relatedAstrologer3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Reply3 = await Replies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Reply3?.setAstrologer) {
|
|
await Reply3.setAstrologer(relatedAstrologer3);
|
|
}
|
|
|
|
const relatedAstrologer4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Reply4 = await Replies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Reply4?.setAstrologer) {
|
|
await Reply4.setAstrologer(relatedAstrologer4);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Questions.bulkCreate(QuestionsData);
|
|
|
|
await Replies.bulkCreate(RepliesData);
|
|
|
|
await Promise.all([
|
|
await associateQuestionWithUser(),
|
|
|
|
await associateQuestionWithAstrologer(),
|
|
|
|
await associateReplyWithQuestion(),
|
|
|
|
await associateReplyWithAstrologer(),
|
|
|
|
// Similar logic for "relation_many"
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('questions', null, {});
|
|
|
|
await queryInterface.bulkDelete('replies', null, {});
|
|
},
|
|
};
|