1004 lines
23 KiB
JavaScript
1004 lines
23 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Events = db.events;
|
|
|
|
const Notifications = db.notifications;
|
|
|
|
const Reviews = db.reviews;
|
|
|
|
const Tickets = db.tickets;
|
|
|
|
const Providers = db.providers;
|
|
|
|
const EventsData = [
|
|
{
|
|
title: 'Concert Night',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-11-10T19:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-10T22:00:00Z'),
|
|
|
|
location: 'City Arena',
|
|
|
|
category: 'transport',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Movie Premiere',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-11-11T20:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-11T23:00:00Z'),
|
|
|
|
location: 'Metro Cinemas Downtown',
|
|
|
|
category: 'transport',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Tech Conference',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-11-12T09:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-12T17:00:00Z'),
|
|
|
|
location: 'Convention Center',
|
|
|
|
category: 'college',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Art Exhibition',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-11-13T10:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-13T18:00:00Z'),
|
|
|
|
location: 'Art Gallery',
|
|
|
|
category: 'college',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Football Match',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_date: new Date('2023-11-14T15:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-14T17:00:00Z'),
|
|
|
|
location: 'City Stadium',
|
|
|
|
category: 'college',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const NotificationsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'Your ticket for Concert Night is confirmed.',
|
|
|
|
sent_date: new Date('2023-11-01T10:05:00Z'),
|
|
|
|
read: false,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'Reminder: Movie Premiere tomorrow at 8 PM.',
|
|
|
|
sent_date: new Date('2023-11-10T20:00:00Z'),
|
|
|
|
read: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'Your refund for Tech Conference has been processed.',
|
|
|
|
sent_date: new Date('2023-11-03T14:30:00Z'),
|
|
|
|
read: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'Art Exhibition starts in 1 hour.',
|
|
|
|
sent_date: new Date('2023-11-13T09:00:00Z'),
|
|
|
|
read: true,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
message: 'Football Match tickets are almost sold out!',
|
|
|
|
sent_date: new Date('2023-11-04T16:00:00Z'),
|
|
|
|
read: false,
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ReviewsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 5,
|
|
|
|
comment: 'Amazing performance and great atmosphere!',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 4,
|
|
|
|
comment: 'Enjoyed the movie, but the seats were uncomfortable.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 3,
|
|
|
|
comment: 'Informative sessions, but could be better organized.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 5,
|
|
|
|
comment: 'Beautiful artwork and well-curated exhibition.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
rating: 4,
|
|
|
|
comment: 'Exciting match, but the food was overpriced.',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const TicketsData = [
|
|
{
|
|
ticket_number: 'TCKT123456',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
booking_date: new Date('2023-11-01T10:00:00Z'),
|
|
|
|
price: 50,
|
|
|
|
status: 'expired',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
ticket_number: 'TCKT123457',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
booking_date: new Date('2023-11-02T12:00:00Z'),
|
|
|
|
price: 15,
|
|
|
|
status: 'booked',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
ticket_number: 'TCKT123458',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
booking_date: new Date('2023-11-03T14:00:00Z'),
|
|
|
|
price: 100,
|
|
|
|
status: 'expired',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
ticket_number: 'TCKT123459',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
booking_date: new Date('2023-11-04T16:00:00Z'),
|
|
|
|
price: 20,
|
|
|
|
status: 'cancelled',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
ticket_number: 'TCKT123460',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
booking_date: new Date('2023-11-05T18:00:00Z'),
|
|
|
|
price: 75,
|
|
|
|
status: 'booked',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ProvidersData = [
|
|
{
|
|
name: 'City Transport Co.',
|
|
},
|
|
|
|
{
|
|
name: 'Skyline Events',
|
|
},
|
|
|
|
{
|
|
name: 'Metro Cinemas',
|
|
},
|
|
|
|
{
|
|
name: 'Greenline Buses',
|
|
},
|
|
|
|
{
|
|
name: 'BlueSky Airlines',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithProvider() {
|
|
const relatedProvider0 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setProvider) {
|
|
await User0.setProvider(relatedProvider0);
|
|
}
|
|
|
|
const relatedProvider1 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setProvider) {
|
|
await User1.setProvider(relatedProvider1);
|
|
}
|
|
|
|
const relatedProvider2 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setProvider) {
|
|
await User2.setProvider(relatedProvider2);
|
|
}
|
|
|
|
const relatedProvider3 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const User3 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (User3?.setProvider) {
|
|
await User3.setProvider(relatedProvider3);
|
|
}
|
|
|
|
const relatedProvider4 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const User4 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (User4?.setProvider) {
|
|
await User4.setProvider(relatedProvider4);
|
|
}
|
|
}
|
|
|
|
async function associateEventWithProvider() {
|
|
const relatedProvider0 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Event0 = await Events.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Event0?.setProvider) {
|
|
await Event0.setProvider(relatedProvider0);
|
|
}
|
|
|
|
const relatedProvider1 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Event1 = await Events.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Event1?.setProvider) {
|
|
await Event1.setProvider(relatedProvider1);
|
|
}
|
|
|
|
const relatedProvider2 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Event2 = await Events.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Event2?.setProvider) {
|
|
await Event2.setProvider(relatedProvider2);
|
|
}
|
|
|
|
const relatedProvider3 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Event3 = await Events.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Event3?.setProvider) {
|
|
await Event3.setProvider(relatedProvider3);
|
|
}
|
|
|
|
const relatedProvider4 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Event4 = await Events.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Event4?.setProvider) {
|
|
await Event4.setProvider(relatedProvider4);
|
|
}
|
|
}
|
|
|
|
async function associateEventWithProvider() {
|
|
const relatedProvider0 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Event0 = await Events.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Event0?.setProvider) {
|
|
await Event0.setProvider(relatedProvider0);
|
|
}
|
|
|
|
const relatedProvider1 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Event1 = await Events.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Event1?.setProvider) {
|
|
await Event1.setProvider(relatedProvider1);
|
|
}
|
|
|
|
const relatedProvider2 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Event2 = await Events.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Event2?.setProvider) {
|
|
await Event2.setProvider(relatedProvider2);
|
|
}
|
|
|
|
const relatedProvider3 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Event3 = await Events.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Event3?.setProvider) {
|
|
await Event3.setProvider(relatedProvider3);
|
|
}
|
|
|
|
const relatedProvider4 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Event4 = await Events.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Event4?.setProvider) {
|
|
await Event4.setProvider(relatedProvider4);
|
|
}
|
|
}
|
|
|
|
async function associateNotificationWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification0 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Notification0?.setUser) {
|
|
await Notification0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification1 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Notification1?.setUser) {
|
|
await Notification1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification2 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Notification2?.setUser) {
|
|
await Notification2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification3 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Notification3?.setUser) {
|
|
await Notification3.setUser(relatedUser3);
|
|
}
|
|
|
|
const relatedUser4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Notification4 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Notification4?.setUser) {
|
|
await Notification4.setUser(relatedUser4);
|
|
}
|
|
}
|
|
|
|
async function associateNotificationWithProvider() {
|
|
const relatedProvider0 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Notification0 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Notification0?.setProvider) {
|
|
await Notification0.setProvider(relatedProvider0);
|
|
}
|
|
|
|
const relatedProvider1 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Notification1 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Notification1?.setProvider) {
|
|
await Notification1.setProvider(relatedProvider1);
|
|
}
|
|
|
|
const relatedProvider2 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Notification2 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Notification2?.setProvider) {
|
|
await Notification2.setProvider(relatedProvider2);
|
|
}
|
|
|
|
const relatedProvider3 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Notification3 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Notification3?.setProvider) {
|
|
await Notification3.setProvider(relatedProvider3);
|
|
}
|
|
|
|
const relatedProvider4 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Notification4 = await Notifications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Notification4?.setProvider) {
|
|
await Notification4.setProvider(relatedProvider4);
|
|
}
|
|
}
|
|
|
|
async function associateReviewWithCustomer() {
|
|
const relatedCustomer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Review0 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Review0?.setCustomer) {
|
|
await Review0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Review1 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Review1?.setCustomer) {
|
|
await Review1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Review2 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Review2?.setCustomer) {
|
|
await Review2.setCustomer(relatedCustomer2);
|
|
}
|
|
|
|
const relatedCustomer3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Review3 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Review3?.setCustomer) {
|
|
await Review3.setCustomer(relatedCustomer3);
|
|
}
|
|
|
|
const relatedCustomer4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Review4 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Review4?.setCustomer) {
|
|
await Review4.setCustomer(relatedCustomer4);
|
|
}
|
|
}
|
|
|
|
async function associateReviewWithEvent() {
|
|
const relatedEvent0 = await Events.findOne({
|
|
offset: Math.floor(Math.random() * (await Events.count())),
|
|
});
|
|
const Review0 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Review0?.setEvent) {
|
|
await Review0.setEvent(relatedEvent0);
|
|
}
|
|
|
|
const relatedEvent1 = await Events.findOne({
|
|
offset: Math.floor(Math.random() * (await Events.count())),
|
|
});
|
|
const Review1 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Review1?.setEvent) {
|
|
await Review1.setEvent(relatedEvent1);
|
|
}
|
|
|
|
const relatedEvent2 = await Events.findOne({
|
|
offset: Math.floor(Math.random() * (await Events.count())),
|
|
});
|
|
const Review2 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Review2?.setEvent) {
|
|
await Review2.setEvent(relatedEvent2);
|
|
}
|
|
|
|
const relatedEvent3 = await Events.findOne({
|
|
offset: Math.floor(Math.random() * (await Events.count())),
|
|
});
|
|
const Review3 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Review3?.setEvent) {
|
|
await Review3.setEvent(relatedEvent3);
|
|
}
|
|
|
|
const relatedEvent4 = await Events.findOne({
|
|
offset: Math.floor(Math.random() * (await Events.count())),
|
|
});
|
|
const Review4 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Review4?.setEvent) {
|
|
await Review4.setEvent(relatedEvent4);
|
|
}
|
|
}
|
|
|
|
async function associateReviewWithProvider() {
|
|
const relatedProvider0 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Review0 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Review0?.setProvider) {
|
|
await Review0.setProvider(relatedProvider0);
|
|
}
|
|
|
|
const relatedProvider1 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Review1 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Review1?.setProvider) {
|
|
await Review1.setProvider(relatedProvider1);
|
|
}
|
|
|
|
const relatedProvider2 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Review2 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Review2?.setProvider) {
|
|
await Review2.setProvider(relatedProvider2);
|
|
}
|
|
|
|
const relatedProvider3 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Review3 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Review3?.setProvider) {
|
|
await Review3.setProvider(relatedProvider3);
|
|
}
|
|
|
|
const relatedProvider4 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Review4 = await Reviews.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Review4?.setProvider) {
|
|
await Review4.setProvider(relatedProvider4);
|
|
}
|
|
}
|
|
|
|
async function associateTicketWithCustomer() {
|
|
const relatedCustomer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Ticket0 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Ticket0?.setCustomer) {
|
|
await Ticket0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Ticket1 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Ticket1?.setCustomer) {
|
|
await Ticket1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Ticket2 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Ticket2?.setCustomer) {
|
|
await Ticket2.setCustomer(relatedCustomer2);
|
|
}
|
|
|
|
const relatedCustomer3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Ticket3 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Ticket3?.setCustomer) {
|
|
await Ticket3.setCustomer(relatedCustomer3);
|
|
}
|
|
|
|
const relatedCustomer4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Ticket4 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Ticket4?.setCustomer) {
|
|
await Ticket4.setCustomer(relatedCustomer4);
|
|
}
|
|
}
|
|
|
|
async function associateTicketWithEvent() {
|
|
const relatedEvent0 = await Events.findOne({
|
|
offset: Math.floor(Math.random() * (await Events.count())),
|
|
});
|
|
const Ticket0 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Ticket0?.setEvent) {
|
|
await Ticket0.setEvent(relatedEvent0);
|
|
}
|
|
|
|
const relatedEvent1 = await Events.findOne({
|
|
offset: Math.floor(Math.random() * (await Events.count())),
|
|
});
|
|
const Ticket1 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Ticket1?.setEvent) {
|
|
await Ticket1.setEvent(relatedEvent1);
|
|
}
|
|
|
|
const relatedEvent2 = await Events.findOne({
|
|
offset: Math.floor(Math.random() * (await Events.count())),
|
|
});
|
|
const Ticket2 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Ticket2?.setEvent) {
|
|
await Ticket2.setEvent(relatedEvent2);
|
|
}
|
|
|
|
const relatedEvent3 = await Events.findOne({
|
|
offset: Math.floor(Math.random() * (await Events.count())),
|
|
});
|
|
const Ticket3 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Ticket3?.setEvent) {
|
|
await Ticket3.setEvent(relatedEvent3);
|
|
}
|
|
|
|
const relatedEvent4 = await Events.findOne({
|
|
offset: Math.floor(Math.random() * (await Events.count())),
|
|
});
|
|
const Ticket4 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Ticket4?.setEvent) {
|
|
await Ticket4.setEvent(relatedEvent4);
|
|
}
|
|
}
|
|
|
|
async function associateTicketWithProvider() {
|
|
const relatedProvider0 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Ticket0 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Ticket0?.setProvider) {
|
|
await Ticket0.setProvider(relatedProvider0);
|
|
}
|
|
|
|
const relatedProvider1 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Ticket1 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Ticket1?.setProvider) {
|
|
await Ticket1.setProvider(relatedProvider1);
|
|
}
|
|
|
|
const relatedProvider2 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Ticket2 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Ticket2?.setProvider) {
|
|
await Ticket2.setProvider(relatedProvider2);
|
|
}
|
|
|
|
const relatedProvider3 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Ticket3 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Ticket3?.setProvider) {
|
|
await Ticket3.setProvider(relatedProvider3);
|
|
}
|
|
|
|
const relatedProvider4 = await Providers.findOne({
|
|
offset: Math.floor(Math.random() * (await Providers.count())),
|
|
});
|
|
const Ticket4 = await Tickets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Ticket4?.setProvider) {
|
|
await Ticket4.setProvider(relatedProvider4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Events.bulkCreate(EventsData);
|
|
|
|
await Notifications.bulkCreate(NotificationsData);
|
|
|
|
await Reviews.bulkCreate(ReviewsData);
|
|
|
|
await Tickets.bulkCreate(TicketsData);
|
|
|
|
await Providers.bulkCreate(ProvidersData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithProvider(),
|
|
|
|
await associateEventWithProvider(),
|
|
|
|
await associateEventWithProvider(),
|
|
|
|
await associateNotificationWithUser(),
|
|
|
|
await associateNotificationWithProvider(),
|
|
|
|
await associateReviewWithCustomer(),
|
|
|
|
await associateReviewWithEvent(),
|
|
|
|
await associateReviewWithProvider(),
|
|
|
|
await associateTicketWithCustomer(),
|
|
|
|
await associateTicketWithEvent(),
|
|
|
|
await associateTicketWithProvider(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('events', null, {});
|
|
|
|
await queryInterface.bulkDelete('notifications', null, {});
|
|
|
|
await queryInterface.bulkDelete('reviews', null, {});
|
|
|
|
await queryInterface.bulkDelete('tickets', null, {});
|
|
|
|
await queryInterface.bulkDelete('providers', null, {});
|
|
},
|
|
};
|