634 lines
15 KiB
JavaScript
634 lines
15 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Bookings = db.bookings;
|
|
|
|
const Companies = db.companies;
|
|
|
|
const Messages = db.messages;
|
|
|
|
const Reports = db.reports;
|
|
|
|
const Company = db.company;
|
|
|
|
const BookingsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
scheduled_start: new Date('2023-11-01T09:00:00Z'),
|
|
|
|
scheduled_end: new Date('2023-11-01T17:00:00Z'),
|
|
|
|
status: 'Cancelled',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
scheduled_start: new Date('2023-11-02T10:00:00Z'),
|
|
|
|
scheduled_end: new Date('2023-11-02T18:00:00Z'),
|
|
|
|
status: 'Completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
|
|
scheduled_start: new Date('2023-11-03T08:00:00Z'),
|
|
|
|
scheduled_end: new Date('2023-11-03T16:00:00Z'),
|
|
|
|
status: 'Completed',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CompaniesData = [
|
|
{
|
|
name: 'TechCorp',
|
|
|
|
address: '123 Tech Street, Silicon Valley',
|
|
|
|
contact_number: '1234567890',
|
|
|
|
email: 'contact@techcorp.com',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'RetailChain',
|
|
|
|
address: '456 Retail Road, Commerce City',
|
|
|
|
contact_number: '0987654321',
|
|
|
|
email: 'info@retailchain.com',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
name: 'WarehouseInc',
|
|
|
|
address: '789 Warehouse Way, Storage Town',
|
|
|
|
contact_number: '1122334455',
|
|
|
|
email: 'support@warehouseinc.com',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const MessagesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'Please confirm the booking details.',
|
|
|
|
sent_at: new Date('2023-10-25T14:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'The client has requested a change in schedule.',
|
|
|
|
sent_at: new Date('2023-10-26T09:30:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
content: 'Can you assist with the stocktake on Friday?',
|
|
|
|
sent_at: new Date('2023-10-27T11:15:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ReportsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
summary: 'Stocktake completed successfully with minor discrepancies noted.',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
summary: 'Client requested additional services post stocktake.',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
summary: 'All items accounted for, no issues reported.',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const CompanyData = [
|
|
{
|
|
name: 'Louis Pasteur',
|
|
},
|
|
|
|
{
|
|
name: 'Sheldon Glashow',
|
|
},
|
|
|
|
{
|
|
name: 'Max Delbruck',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateUserWithCompany() {
|
|
const relatedCompany0 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (User0?.setCompany) {
|
|
await User0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (User1?.setCompany) {
|
|
await User1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (User2?.setCompany) {
|
|
await User2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
async function associateBookingWithClient() {
|
|
const relatedClient0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking0 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Booking0?.setClient) {
|
|
await Booking0.setClient(relatedClient0);
|
|
}
|
|
|
|
const relatedClient1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking1 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Booking1?.setClient) {
|
|
await Booking1.setClient(relatedClient1);
|
|
}
|
|
|
|
const relatedClient2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking2 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Booking2?.setClient) {
|
|
await Booking2.setClient(relatedClient2);
|
|
}
|
|
}
|
|
|
|
async function associateBookingWithCoordinator() {
|
|
const relatedCoordinator0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking0 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Booking0?.setCoordinator) {
|
|
await Booking0.setCoordinator(relatedCoordinator0);
|
|
}
|
|
|
|
const relatedCoordinator1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking1 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Booking1?.setCoordinator) {
|
|
await Booking1.setCoordinator(relatedCoordinator1);
|
|
}
|
|
|
|
const relatedCoordinator2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Booking2 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Booking2?.setCoordinator) {
|
|
await Booking2.setCoordinator(relatedCoordinator2);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateBookingWithCompany() {
|
|
const relatedCompany0 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Booking0 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Booking0?.setCompany) {
|
|
await Booking0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Booking1 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Booking1?.setCompany) {
|
|
await Booking1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Booking2 = await Bookings.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Booking2?.setCompany) {
|
|
await Booking2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
async function associateCompanyWithCompany() {
|
|
const relatedCompany0 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Company0 = await Companies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Company0?.setCompany) {
|
|
await Company0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Company1 = await Companies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Company1?.setCompany) {
|
|
await Company1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Company2 = await Companies.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Company2?.setCompany) {
|
|
await Company2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
async function associateMessageWithSender() {
|
|
const relatedSender0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setSender) {
|
|
await Message0.setSender(relatedSender0);
|
|
}
|
|
|
|
const relatedSender1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setSender) {
|
|
await Message1.setSender(relatedSender1);
|
|
}
|
|
|
|
const relatedSender2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setSender) {
|
|
await Message2.setSender(relatedSender2);
|
|
}
|
|
}
|
|
|
|
async function associateMessageWithReceiver() {
|
|
const relatedReceiver0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setReceiver) {
|
|
await Message0.setReceiver(relatedReceiver0);
|
|
}
|
|
|
|
const relatedReceiver1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setReceiver) {
|
|
await Message1.setReceiver(relatedReceiver1);
|
|
}
|
|
|
|
const relatedReceiver2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setReceiver) {
|
|
await Message2.setReceiver(relatedReceiver2);
|
|
}
|
|
}
|
|
|
|
async function associateMessageWithCompany() {
|
|
const relatedCompany0 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Message0 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Message0?.setCompany) {
|
|
await Message0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Message1 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Message1?.setCompany) {
|
|
await Message1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Message2 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Message2?.setCompany) {
|
|
await Message2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
async function associateReportWithBooking() {
|
|
const relatedBooking0 = await Bookings.findOne({
|
|
offset: Math.floor(Math.random() * (await Bookings.count())),
|
|
});
|
|
const Report0 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Report0?.setBooking) {
|
|
await Report0.setBooking(relatedBooking0);
|
|
}
|
|
|
|
const relatedBooking1 = await Bookings.findOne({
|
|
offset: Math.floor(Math.random() * (await Bookings.count())),
|
|
});
|
|
const Report1 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Report1?.setBooking) {
|
|
await Report1.setBooking(relatedBooking1);
|
|
}
|
|
|
|
const relatedBooking2 = await Bookings.findOne({
|
|
offset: Math.floor(Math.random() * (await Bookings.count())),
|
|
});
|
|
const Report2 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Report2?.setBooking) {
|
|
await Report2.setBooking(relatedBooking2);
|
|
}
|
|
}
|
|
|
|
async function associateReportWithSupervisor() {
|
|
const relatedSupervisor0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Report0 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Report0?.setSupervisor) {
|
|
await Report0.setSupervisor(relatedSupervisor0);
|
|
}
|
|
|
|
const relatedSupervisor1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Report1 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Report1?.setSupervisor) {
|
|
await Report1.setSupervisor(relatedSupervisor1);
|
|
}
|
|
|
|
const relatedSupervisor2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Report2 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Report2?.setSupervisor) {
|
|
await Report2.setSupervisor(relatedSupervisor2);
|
|
}
|
|
}
|
|
|
|
async function associateReportWithCompany() {
|
|
const relatedCompany0 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Report0 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Report0?.setCompany) {
|
|
await Report0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Report1 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Report1?.setCompany) {
|
|
await Report1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Company.findOne({
|
|
offset: Math.floor(Math.random() * (await Company.count())),
|
|
});
|
|
const Report2 = await Reports.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Report2?.setCompany) {
|
|
await Report2.setCompany(relatedCompany2);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Bookings.bulkCreate(BookingsData);
|
|
|
|
await Companies.bulkCreate(CompaniesData);
|
|
|
|
await Messages.bulkCreate(MessagesData);
|
|
|
|
await Reports.bulkCreate(ReportsData);
|
|
|
|
await Company.bulkCreate(CompanyData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateUserWithCompany(),
|
|
|
|
await associateBookingWithClient(),
|
|
|
|
await associateBookingWithCoordinator(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateBookingWithCompany(),
|
|
|
|
await associateCompanyWithCompany(),
|
|
|
|
await associateMessageWithSender(),
|
|
|
|
await associateMessageWithReceiver(),
|
|
|
|
await associateMessageWithCompany(),
|
|
|
|
await associateReportWithBooking(),
|
|
|
|
await associateReportWithSupervisor(),
|
|
|
|
await associateReportWithCompany(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('bookings', null, {});
|
|
|
|
await queryInterface.bulkDelete('companies', null, {});
|
|
|
|
await queryInterface.bulkDelete('messages', null, {});
|
|
|
|
await queryInterface.bulkDelete('reports', null, {});
|
|
|
|
await queryInterface.bulkDelete('company', null, {});
|
|
},
|
|
};
|