33583/backend/src/db/seeders/20231127130745-sample-data.js
2025-08-23 16:46:34 +00:00

303 lines
6.8 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const ApiUsages = db.api_usages;
const EmailAnalyses = db.email_analyses;
const Feedbacks = db.feedbacks;
const SystemNotifications = db.system_notifications;
const ApiUsagesData = [
{
api_name: 'VirusTotal',
usage_count: 150,
last_used: new Date('2023-10-05T12:00:00Z'),
},
{
api_name: 'PhishTank',
usage_count: 120,
last_used: new Date('2023-10-05T12:30:00Z'),
},
{
api_name: 'Google Safe Browsing',
usage_count: 130,
last_used: new Date('2023-10-05T13:00:00Z'),
},
{
api_name: 'VirusTotal',
usage_count: 160,
last_used: new Date('2023-10-06T10:00:00Z'),
},
];
const EmailAnalysesData = [
{
email_content: 'Suspicious email from unknown sender',
// type code here for "files" field
threat_level: 'HighRisk',
risk_score: 9.2,
// type code here for "relation_one" field
analysis_date: new Date('2023-10-01T10:00:00Z'),
},
{
email_content: 'Phishing attempt with fake invoice',
// type code here for "files" field
threat_level: 'Safe',
risk_score: 6.5,
// type code here for "relation_one" field
analysis_date: new Date('2023-10-02T11:30:00Z'),
},
{
email_content: 'Legitimate newsletter from trusted source',
// type code here for "files" field
threat_level: 'HighRisk',
risk_score: 1,
// type code here for "relation_one" field
analysis_date: new Date('2023-10-03T09:15:00Z'),
},
{
email_content: 'Tech support scam email',
// type code here for "files" field
threat_level: 'HighRisk',
risk_score: 8.7,
// type code here for "relation_one" field
analysis_date: new Date('2023-10-04T14:45:00Z'),
},
];
const FeedbacksData = [
{
// type code here for "relation_one" field
feedback_content: 'False positive detected in email analysis',
feedback_type: 'FalseNegative',
submitted_at: new Date('2023-10-01T15:00:00Z'),
},
{
// type code here for "relation_one" field
feedback_content: 'Improvement suggestion for risk scoring algorithm',
feedback_type: 'ImprovementSuggestion',
submitted_at: new Date('2023-10-02T16:30:00Z'),
},
{
// type code here for "relation_one" field
feedback_content: 'False negative in phishing detection',
feedback_type: 'FalsePositive',
submitted_at: new Date('2023-10-03T14:45:00Z'),
},
{
// type code here for "relation_one" field
feedback_content: 'System performance is satisfactory',
feedback_type: 'FalsePositive',
submitted_at: new Date('2023-10-04T13:20:00Z'),
},
];
const SystemNotificationsData = [
{
notification_message: 'High threat detected in recent analysis',
notification_type: 'APIQuotaWarning',
notification_date: new Date('2023-10-05T14:00:00Z'),
},
{
notification_message: 'Bulk analysis completed successfully',
notification_type: 'BulkAnalysisCompletion',
notification_date: new Date('2023-10-05T15:30:00Z'),
},
{
notification_message: 'API usage reached 80% of quota',
notification_type: 'APIQuotaWarning',
notification_date: new Date('2023-10-05T16:00:00Z'),
},
{
notification_message: 'System health check passed',
notification_type: 'BulkAnalysisCompletion',
notification_date: new Date('2023-10-05T17:00:00Z'),
},
];
// Similar logic for "relation_many"
async function associateEmailAnalysisWithAnalyzed_by() {
const relatedAnalyzed_by0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const EmailAnalysis0 = await EmailAnalyses.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (EmailAnalysis0?.setAnalyzed_by) {
await EmailAnalysis0.setAnalyzed_by(relatedAnalyzed_by0);
}
const relatedAnalyzed_by1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const EmailAnalysis1 = await EmailAnalyses.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (EmailAnalysis1?.setAnalyzed_by) {
await EmailAnalysis1.setAnalyzed_by(relatedAnalyzed_by1);
}
const relatedAnalyzed_by2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const EmailAnalysis2 = await EmailAnalyses.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (EmailAnalysis2?.setAnalyzed_by) {
await EmailAnalysis2.setAnalyzed_by(relatedAnalyzed_by2);
}
const relatedAnalyzed_by3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const EmailAnalysis3 = await EmailAnalyses.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (EmailAnalysis3?.setAnalyzed_by) {
await EmailAnalysis3.setAnalyzed_by(relatedAnalyzed_by3);
}
}
async function associateFeedbackWithSubmitted_by() {
const relatedSubmitted_by0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Feedback0 = await Feedbacks.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Feedback0?.setSubmitted_by) {
await Feedback0.setSubmitted_by(relatedSubmitted_by0);
}
const relatedSubmitted_by1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Feedback1 = await Feedbacks.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Feedback1?.setSubmitted_by) {
await Feedback1.setSubmitted_by(relatedSubmitted_by1);
}
const relatedSubmitted_by2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Feedback2 = await Feedbacks.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Feedback2?.setSubmitted_by) {
await Feedback2.setSubmitted_by(relatedSubmitted_by2);
}
const relatedSubmitted_by3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Feedback3 = await Feedbacks.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Feedback3?.setSubmitted_by) {
await Feedback3.setSubmitted_by(relatedSubmitted_by3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await ApiUsages.bulkCreate(ApiUsagesData);
await EmailAnalyses.bulkCreate(EmailAnalysesData);
await Feedbacks.bulkCreate(FeedbacksData);
await SystemNotifications.bulkCreate(SystemNotificationsData);
await Promise.all([
// Similar logic for "relation_many"
await associateEmailAnalysisWithAnalyzed_by(),
await associateFeedbackWithSubmitted_by(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('api_usages', null, {});
await queryInterface.bulkDelete('email_analyses', null, {});
await queryInterface.bulkDelete('feedbacks', null, {});
await queryInterface.bulkDelete('system_notifications', null, {});
},
};