666 lines
15 KiB
JavaScript
666 lines
15 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Applications = db.applications;
|
|
|
|
const Jobs = db.jobs;
|
|
|
|
const Messages = db.messages;
|
|
|
|
const Profiles = db.profiles;
|
|
|
|
const ApplicationsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
application_date: new Date('2023-10-06T15:00:00Z'),
|
|
|
|
status: 'applied',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
application_date: new Date('2023-10-07T16:00:00Z'),
|
|
|
|
status: 'rejected',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
application_date: new Date('2023-10-08T17:00:00Z'),
|
|
|
|
status: 'shortlisted',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
application_date: new Date('2023-10-09T18:00:00Z'),
|
|
|
|
status: 'hired',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
application_date: new Date('2023-10-10T19:00:00Z'),
|
|
|
|
status: 'rejected',
|
|
},
|
|
];
|
|
|
|
const JobsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
title: 'Wedding Planner',
|
|
|
|
category: 'sound',
|
|
|
|
description: 'Plan and coordinate wedding events.',
|
|
|
|
location: 'New York',
|
|
|
|
budget: 5000,
|
|
|
|
event_date: new Date('2023-12-15T00:00:00Z'),
|
|
|
|
status: 'closed',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
title: 'Catering Service',
|
|
|
|
category: 'production',
|
|
|
|
description: 'Provide catering for corporate events.',
|
|
|
|
location: 'Los Angeles',
|
|
|
|
budget: 3000,
|
|
|
|
event_date: new Date('2023-11-20T00:00:00Z'),
|
|
|
|
status: 'closed',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
title: 'Lighting Technician',
|
|
|
|
category: 'decoration',
|
|
|
|
description: 'Setup and manage event lighting.',
|
|
|
|
location: 'San Francisco',
|
|
|
|
budget: 2000,
|
|
|
|
event_date: new Date('2023-12-01T00:00:00Z'),
|
|
|
|
status: 'closed',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
title: 'Sound Engineer',
|
|
|
|
category: 'food',
|
|
|
|
description: 'Manage sound systems for events.',
|
|
|
|
location: 'New York',
|
|
|
|
budget: 2500,
|
|
|
|
event_date: new Date('2023-12-10T00:00:00Z'),
|
|
|
|
status: 'closed',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
title: 'Decoration Specialist',
|
|
|
|
category: 'lighting',
|
|
|
|
description: 'Decorate venues for special occasions.',
|
|
|
|
location: 'Los Angeles',
|
|
|
|
budget: 1500,
|
|
|
|
event_date: new Date('2023-11-25T00:00:00Z'),
|
|
|
|
status: 'closed',
|
|
},
|
|
];
|
|
|
|
const MessagesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
message_text:
|
|
'We are interested in your profile for the Wedding Planner position.',
|
|
|
|
timestamp: new Date('2023-10-11T20:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
message_text:
|
|
'Your application for the Catering Service has been shortlisted.',
|
|
|
|
timestamp: new Date('2023-10-12T21:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
message_text:
|
|
'Congratulations! You have been hired for the Lighting Technician role.',
|
|
|
|
timestamp: new Date('2023-10-13T22:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
message_text:
|
|
'Unfortunately, your application for the Sound Engineer position was not successful.',
|
|
|
|
timestamp: new Date('2023-10-14T23:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
message_text:
|
|
'We would like to discuss your application for the Decoration Specialist role.',
|
|
|
|
timestamp: new Date('2023-10-15T00:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const ProfilesData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
skills: 'Event planning, coordination',
|
|
|
|
experience_years: 5,
|
|
|
|
// type code here for "files" field
|
|
|
|
portfolio_url: 'https://example.com/portfolio/johndoe',
|
|
|
|
availability: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
skills: 'Catering, food service',
|
|
|
|
experience_years: 3,
|
|
|
|
// type code here for "files" field
|
|
|
|
portfolio_url: 'https://example.com/portfolio/janesmith',
|
|
|
|
availability: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
skills: 'Lighting setup, technical support',
|
|
|
|
experience_years: 4,
|
|
|
|
// type code here for "files" field
|
|
|
|
portfolio_url: 'https://example.com/portfolio/johndoe2',
|
|
|
|
availability: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
skills: 'Sound engineering, audio mixing',
|
|
|
|
experience_years: 6,
|
|
|
|
// type code here for "files" field
|
|
|
|
portfolio_url: 'https://example.com/portfolio/janesmith2',
|
|
|
|
availability: true,
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
skills: 'Decoration, design',
|
|
|
|
experience_years: 2,
|
|
|
|
// type code here for "files" field
|
|
|
|
portfolio_url: 'https://example.com/portfolio/johndoe3',
|
|
|
|
availability: false,
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateApplicationWithJob() {
|
|
const relatedJob0 = await Jobs.findOne({
|
|
offset: Math.floor(Math.random() * (await Jobs.count())),
|
|
});
|
|
const Application0 = await Applications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Application0?.setJob) {
|
|
await Application0.setJob(relatedJob0);
|
|
}
|
|
|
|
const relatedJob1 = await Jobs.findOne({
|
|
offset: Math.floor(Math.random() * (await Jobs.count())),
|
|
});
|
|
const Application1 = await Applications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Application1?.setJob) {
|
|
await Application1.setJob(relatedJob1);
|
|
}
|
|
|
|
const relatedJob2 = await Jobs.findOne({
|
|
offset: Math.floor(Math.random() * (await Jobs.count())),
|
|
});
|
|
const Application2 = await Applications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Application2?.setJob) {
|
|
await Application2.setJob(relatedJob2);
|
|
}
|
|
|
|
const relatedJob3 = await Jobs.findOne({
|
|
offset: Math.floor(Math.random() * (await Jobs.count())),
|
|
});
|
|
const Application3 = await Applications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Application3?.setJob) {
|
|
await Application3.setJob(relatedJob3);
|
|
}
|
|
|
|
const relatedJob4 = await Jobs.findOne({
|
|
offset: Math.floor(Math.random() * (await Jobs.count())),
|
|
});
|
|
const Application4 = await Applications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Application4?.setJob) {
|
|
await Application4.setJob(relatedJob4);
|
|
}
|
|
}
|
|
|
|
async function associateApplicationWithProfessional() {
|
|
const relatedProfessional0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Application0 = await Applications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Application0?.setProfessional) {
|
|
await Application0.setProfessional(relatedProfessional0);
|
|
}
|
|
|
|
const relatedProfessional1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Application1 = await Applications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Application1?.setProfessional) {
|
|
await Application1.setProfessional(relatedProfessional1);
|
|
}
|
|
|
|
const relatedProfessional2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Application2 = await Applications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Application2?.setProfessional) {
|
|
await Application2.setProfessional(relatedProfessional2);
|
|
}
|
|
|
|
const relatedProfessional3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Application3 = await Applications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Application3?.setProfessional) {
|
|
await Application3.setProfessional(relatedProfessional3);
|
|
}
|
|
|
|
const relatedProfessional4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Application4 = await Applications.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Application4?.setProfessional) {
|
|
await Application4.setProfessional(relatedProfessional4);
|
|
}
|
|
}
|
|
|
|
async function associateJobWithCompany() {
|
|
const relatedCompany0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Job0 = await Jobs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Job0?.setCompany) {
|
|
await Job0.setCompany(relatedCompany0);
|
|
}
|
|
|
|
const relatedCompany1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Job1 = await Jobs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Job1?.setCompany) {
|
|
await Job1.setCompany(relatedCompany1);
|
|
}
|
|
|
|
const relatedCompany2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Job2 = await Jobs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Job2?.setCompany) {
|
|
await Job2.setCompany(relatedCompany2);
|
|
}
|
|
|
|
const relatedCompany3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Job3 = await Jobs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Job3?.setCompany) {
|
|
await Job3.setCompany(relatedCompany3);
|
|
}
|
|
|
|
const relatedCompany4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Job4 = await Jobs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Job4?.setCompany) {
|
|
await Job4.setCompany(relatedCompany4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedSender3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message3 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Message3?.setSender) {
|
|
await Message3.setSender(relatedSender3);
|
|
}
|
|
|
|
const relatedSender4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message4 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Message4?.setSender) {
|
|
await Message4.setSender(relatedSender4);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const relatedReceiver3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message3 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Message3?.setReceiver) {
|
|
await Message3.setReceiver(relatedReceiver3);
|
|
}
|
|
|
|
const relatedReceiver4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Message4 = await Messages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Message4?.setReceiver) {
|
|
await Message4.setReceiver(relatedReceiver4);
|
|
}
|
|
}
|
|
|
|
async function associateProfileWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Profile0 = await Profiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Profile0?.setUser) {
|
|
await Profile0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Profile1 = await Profiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Profile1?.setUser) {
|
|
await Profile1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Profile2 = await Profiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Profile2?.setUser) {
|
|
await Profile2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Profile3 = await Profiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Profile3?.setUser) {
|
|
await Profile3.setUser(relatedUser3);
|
|
}
|
|
|
|
const relatedUser4 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Profile4 = await Profiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Profile4?.setUser) {
|
|
await Profile4.setUser(relatedUser4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Applications.bulkCreate(ApplicationsData);
|
|
|
|
await Jobs.bulkCreate(JobsData);
|
|
|
|
await Messages.bulkCreate(MessagesData);
|
|
|
|
await Profiles.bulkCreate(ProfilesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateApplicationWithJob(),
|
|
|
|
await associateApplicationWithProfessional(),
|
|
|
|
await associateJobWithCompany(),
|
|
|
|
await associateMessageWithSender(),
|
|
|
|
await associateMessageWithReceiver(),
|
|
|
|
await associateProfileWithUser(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('applications', null, {});
|
|
|
|
await queryInterface.bulkDelete('jobs', null, {});
|
|
|
|
await queryInterface.bulkDelete('messages', null, {});
|
|
|
|
await queryInterface.bulkDelete('profiles', null, {});
|
|
},
|
|
};
|