2073 lines
39 KiB
JavaScript
2073 lines
39 KiB
JavaScript
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Customers = db.customers;
|
|
|
|
const Tags = db.tags;
|
|
|
|
const Chats = db.chats;
|
|
|
|
const Messages = db.messages;
|
|
|
|
const Templates = db.templates;
|
|
|
|
const Broadcasts = db.broadcasts;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const CustomersData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Wang Hong",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"phone": "+8613910000001",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"source": "Website",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_contacted": new Date('2026-01-26T09:15:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"session_status": "open",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"note": "Prefers evening contact",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Lila Sharma",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"phone": "+919876543210",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"source": "Facebook Ad",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_contacted": new Date('2026-01-24T14:40:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"session_status": "closed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"note": "Interested in pricing details",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "John Miller",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"phone": "+12025550123",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"source": "Referral",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_contacted": new Date('2026-01-20T11:05:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"session_status": "open",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"note": "Bulk order last month",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Aisha Khan",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"phone": "+971501234567",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"source": "Organic Search",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_contacted": new Date('2026-01-27T07:30:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"session_status": "needs_template",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"note": "Asked about customization",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const TagsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "VIP",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"color": "#FFD700",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "New Lead",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"color": "#34D399",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "After Sales",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"color": "#60A5FA",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Wholesale",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"color": "#F97316",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const ChatsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"topic": "Order 2026-001 Inquiry",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "template_required",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"unread_count": 2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_message_preview": "Hello, the shipment is scheduled for tomorrow",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_message_time": new Date('2026-01-26T09:10:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"topic": "Pricing question for bulk order",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "open",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"unread_count": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_message_preview": "Thanks for the information, we will confirm",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_message_time": new Date('2026-01-20T11:05:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"topic": "Customization request",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "template_required",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"unread_count": 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_message_preview": "Can you provide mockups for approval",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_message_time": new Date('2026-01-27T07:28:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"topic": "Refund follow up",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "open",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"unread_count": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_message_preview": "Refund processed on our side, awaiting confirmation",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"last_message_time": new Date('2026-01-22T16:18:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const MessagesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Your order will ship tomorrow between 9 and 12.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"message_type": "image",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_time": new Date('2026-01-26T09:10:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_from_customer": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Can you offer a discount for 500 units?",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"message_type": "image",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_time": new Date('2026-01-20T10:55:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_from_customer": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Please review the attached mockup and confirm.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"message_type": "image",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_time": new Date('2026-01-27T07:28:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_from_customer": false,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "I have not received the refund yet.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"message_type": "image",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "images" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_time": new Date('2026-01-22T15:50:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_from_customer": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const TemplatesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Order Shipment Notice",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "follow_up",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "pending",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Hello {{name}}, your order {{order}} has been shipped and is expected to arrive on {{date}}.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"variables": "name,order,date",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"example": "Hello Wang Hong, your order 2026-001 has been shipped and is expected to arrive on 2026-01-28.",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Pricing Follow Up",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "service",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "approved",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Hi {{name}}, following up on your pricing inquiry for order {{order}}. Would you like a quote revision?",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"variables": "name,order",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"example": "Hi John Miller, following up on your pricing inquiry for order 2026-070.",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Refund Processed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "notification",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "rejected",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Dear {{name}}, your refund for order {{order}} has been processed. Expect funds in 3-5 business days.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"variables": "name,order",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"example": "Dear Marco Rossi, your refund for order 2025-981 has been processed.",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Reengagement Offer",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"category": "service",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "approved",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content": "Hello {{name}}, we miss you. Enjoy 10 percent off your next order with code RECONNECT10.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"variables": "name",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"example": "Hello Lila Sharma, enjoy 10 percent off your next order with code RECONNECT10.",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const BroadcastsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "Monthly Newsletter January",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"scheduled_at": new Date('2026-02-01T08:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date('2020-01-01T00:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"variables": "name:multi",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "scheduled",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"preview": "Hello {{name}}, enjoy 10 percent off your next order with code RECONNECT10.",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "Shipment Alerts Batch",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"scheduled_at": new Date('2026-01-26T08:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date('2026-01-26T09:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"variables": "name,order,date",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "scheduled",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"preview": "Hello Wang Hong, your order 2026-001 has been shipped and is expected to arrive on 2026-01-28.",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "Refund Status Update",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"scheduled_at": new Date('2026-01-22T16:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date('2026-01-22T16:18:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"variables": "name,order",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "failed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"preview": "Dear Marco Rossi, your refund for order 2025-981 has been processed.",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "Pricing Campaign",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"scheduled_at": new Date('2026-01-24T14:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"sent_at": new Date('2026-01-24T14:38:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"variables": "name,order",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "scheduled",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"preview": "Hi John Miller, following up on your pricing inquiry for order 2026-070.",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateChatWithCustomer() {
|
|
|
|
const relatedCustomer0 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Chat0 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Chat0?.setCustomer)
|
|
{
|
|
await
|
|
Chat0.
|
|
setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Chat1 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Chat1?.setCustomer)
|
|
{
|
|
await
|
|
Chat1.
|
|
setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Chat2 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Chat2?.setCustomer)
|
|
{
|
|
await
|
|
Chat2.
|
|
setCustomer(relatedCustomer2);
|
|
}
|
|
|
|
const relatedCustomer3 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Chat3 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (Chat3?.setCustomer)
|
|
{
|
|
await
|
|
Chat3.
|
|
setCustomer(relatedCustomer3);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateChatWithAssignee() {
|
|
|
|
const relatedAssignee0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Chat0 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Chat0?.setAssignee)
|
|
{
|
|
await
|
|
Chat0.
|
|
setAssignee(relatedAssignee0);
|
|
}
|
|
|
|
const relatedAssignee1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Chat1 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Chat1?.setAssignee)
|
|
{
|
|
await
|
|
Chat1.
|
|
setAssignee(relatedAssignee1);
|
|
}
|
|
|
|
const relatedAssignee2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Chat2 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Chat2?.setAssignee)
|
|
{
|
|
await
|
|
Chat2.
|
|
setAssignee(relatedAssignee2);
|
|
}
|
|
|
|
const relatedAssignee3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Chat3 = await Chats.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (Chat3?.setAssignee)
|
|
{
|
|
await
|
|
Chat3.
|
|
setAssignee(relatedAssignee3);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateMessageWithChat() {
|
|
|
|
const relatedChat0 = await Chats.findOne({
|
|
offset: Math.floor(Math.random() * (await Chats.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Message0?.setChat)
|
|
{
|
|
await
|
|
Message0.
|
|
setChat(relatedChat0);
|
|
}
|
|
|
|
const relatedChat1 = await Chats.findOne({
|
|
offset: Math.floor(Math.random() * (await Chats.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Message1?.setChat)
|
|
{
|
|
await
|
|
Message1.
|
|
setChat(relatedChat1);
|
|
}
|
|
|
|
const relatedChat2 = await Chats.findOne({
|
|
offset: Math.floor(Math.random() * (await Chats.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Message2?.setChat)
|
|
{
|
|
await
|
|
Message2.
|
|
setChat(relatedChat2);
|
|
}
|
|
|
|
const relatedChat3 = await Chats.findOne({
|
|
offset: Math.floor(Math.random() * (await Chats.count())),
|
|
});
|
|
const Message3 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (Message3?.setChat)
|
|
{
|
|
await
|
|
Message3.
|
|
setChat(relatedChat3);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateMessageWithSender_user() {
|
|
|
|
const relatedSender_user0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Message0?.setSender_user)
|
|
{
|
|
await
|
|
Message0.
|
|
setSender_user(relatedSender_user0);
|
|
}
|
|
|
|
const relatedSender_user1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Message1?.setSender_user)
|
|
{
|
|
await
|
|
Message1.
|
|
setSender_user(relatedSender_user1);
|
|
}
|
|
|
|
const relatedSender_user2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Message2?.setSender_user)
|
|
{
|
|
await
|
|
Message2.
|
|
setSender_user(relatedSender_user2);
|
|
}
|
|
|
|
const relatedSender_user3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message3 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (Message3?.setSender_user)
|
|
{
|
|
await
|
|
Message3.
|
|
setSender_user(relatedSender_user3);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateMessageWithSender_customer() {
|
|
|
|
const relatedSender_customer0 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Message0?.setSender_customer)
|
|
{
|
|
await
|
|
Message0.
|
|
setSender_customer(relatedSender_customer0);
|
|
}
|
|
|
|
const relatedSender_customer1 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Message1?.setSender_customer)
|
|
{
|
|
await
|
|
Message1.
|
|
setSender_customer(relatedSender_customer1);
|
|
}
|
|
|
|
const relatedSender_customer2 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Message2?.setSender_customer)
|
|
{
|
|
await
|
|
Message2.
|
|
setSender_customer(relatedSender_customer2);
|
|
}
|
|
|
|
const relatedSender_customer3 = await Customers.findOne({
|
|
offset: Math.floor(Math.random() * (await Customers.count())),
|
|
});
|
|
const Message3 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (Message3?.setSender_customer)
|
|
{
|
|
await
|
|
Message3.
|
|
setSender_customer(relatedSender_customer3);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateBroadcastWithTemplate() {
|
|
|
|
const relatedTemplate0 = await Templates.findOne({
|
|
offset: Math.floor(Math.random() * (await Templates.count())),
|
|
});
|
|
const Broadcast0 = await Broadcasts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Broadcast0?.setTemplate)
|
|
{
|
|
await
|
|
Broadcast0.
|
|
setTemplate(relatedTemplate0);
|
|
}
|
|
|
|
const relatedTemplate1 = await Templates.findOne({
|
|
offset: Math.floor(Math.random() * (await Templates.count())),
|
|
});
|
|
const Broadcast1 = await Broadcasts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Broadcast1?.setTemplate)
|
|
{
|
|
await
|
|
Broadcast1.
|
|
setTemplate(relatedTemplate1);
|
|
}
|
|
|
|
const relatedTemplate2 = await Templates.findOne({
|
|
offset: Math.floor(Math.random() * (await Templates.count())),
|
|
});
|
|
const Broadcast2 = await Broadcasts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Broadcast2?.setTemplate)
|
|
{
|
|
await
|
|
Broadcast2.
|
|
setTemplate(relatedTemplate2);
|
|
}
|
|
|
|
const relatedTemplate3 = await Templates.findOne({
|
|
offset: Math.floor(Math.random() * (await Templates.count())),
|
|
});
|
|
const Broadcast3 = await Broadcasts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (Broadcast3?.setTemplate)
|
|
{
|
|
await
|
|
Broadcast3.
|
|
setTemplate(relatedTemplate3);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateBroadcastWithSender() {
|
|
|
|
const relatedSender0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Broadcast0 = await Broadcasts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Broadcast0?.setSender)
|
|
{
|
|
await
|
|
Broadcast0.
|
|
setSender(relatedSender0);
|
|
}
|
|
|
|
const relatedSender1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Broadcast1 = await Broadcasts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Broadcast1?.setSender)
|
|
{
|
|
await
|
|
Broadcast1.
|
|
setSender(relatedSender1);
|
|
}
|
|
|
|
const relatedSender2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Broadcast2 = await Broadcasts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Broadcast2?.setSender)
|
|
{
|
|
await
|
|
Broadcast2.
|
|
setSender(relatedSender2);
|
|
}
|
|
|
|
const relatedSender3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Broadcast3 = await Broadcasts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3
|
|
});
|
|
if (Broadcast3?.setSender)
|
|
{
|
|
await
|
|
Broadcast3.
|
|
setSender(relatedSender3);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Customers.bulkCreate(CustomersData);
|
|
|
|
|
|
|
|
|
|
await Tags.bulkCreate(TagsData);
|
|
|
|
|
|
|
|
|
|
await Chats.bulkCreate(ChatsData);
|
|
|
|
|
|
|
|
|
|
await Messages.bulkCreate(MessagesData);
|
|
|
|
|
|
|
|
|
|
await Templates.bulkCreate(TemplatesData);
|
|
|
|
|
|
|
|
|
|
await Broadcasts.bulkCreate(BroadcastsData);
|
|
|
|
|
|
await Promise.all([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateChatWithCustomer(),
|
|
|
|
|
|
|
|
|
|
await associateChatWithAssignee(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateMessageWithChat(),
|
|
|
|
|
|
|
|
|
|
await associateMessageWithSender_user(),
|
|
|
|
|
|
|
|
|
|
await associateMessageWithSender_customer(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateBroadcastWithTemplate(),
|
|
|
|
|
|
|
|
|
|
await associateBroadcastWithSender(),
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await queryInterface.bulkDelete('customers', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('tags', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('chats', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('messages', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('templates', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('broadcasts', null, {});
|
|
|
|
|
|
},
|
|
}; |