283 lines
6.4 KiB
JavaScript
283 lines
6.4 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const JobDescriptions = db.job_descriptions;
|
|
|
|
const Resumes = db.resumes;
|
|
|
|
const Suggestions = db.suggestions;
|
|
|
|
const JobDescriptionsData = [
|
|
{
|
|
title: 'Frontend Developer',
|
|
|
|
description: 'Develop and maintain web applications using React.js',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Business Analyst',
|
|
|
|
description: 'Analyze business processes and provide solutions',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'IT Support Specialist',
|
|
|
|
description: 'Provide technical support and troubleshooting',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Content Writer',
|
|
|
|
description: 'Create engaging content for various platforms',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
const ResumesData = [
|
|
{
|
|
title: 'Software Engineer Resume',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
title: 'Data Analyst Resume',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
title: 'Project Manager Resume',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
title: 'Graphic Designer Resume',
|
|
|
|
// type code here for "files" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const SuggestionsData = [
|
|
{
|
|
content: 'Add more technical skills',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'Include more data visualization tools',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'Highlight leadership experience',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
content: 'Showcase design portfolio',
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateJobDescriptionWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const JobDescription0 = await JobDescriptions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (JobDescription0?.setUser) {
|
|
await JobDescription0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const JobDescription1 = await JobDescriptions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (JobDescription1?.setUser) {
|
|
await JobDescription1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const JobDescription2 = await JobDescriptions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (JobDescription2?.setUser) {
|
|
await JobDescription2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const JobDescription3 = await JobDescriptions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (JobDescription3?.setUser) {
|
|
await JobDescription3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
async function associateResumeWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Resume0 = await Resumes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Resume0?.setUser) {
|
|
await Resume0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Resume1 = await Resumes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Resume1?.setUser) {
|
|
await Resume1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Resume2 = await Resumes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Resume2?.setUser) {
|
|
await Resume2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Resume3 = await Resumes.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Resume3?.setUser) {
|
|
await Resume3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateSuggestionWithResume() {
|
|
const relatedResume0 = await Resumes.findOne({
|
|
offset: Math.floor(Math.random() * (await Resumes.count())),
|
|
});
|
|
const Suggestion0 = await Suggestions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Suggestion0?.setResume) {
|
|
await Suggestion0.setResume(relatedResume0);
|
|
}
|
|
|
|
const relatedResume1 = await Resumes.findOne({
|
|
offset: Math.floor(Math.random() * (await Resumes.count())),
|
|
});
|
|
const Suggestion1 = await Suggestions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Suggestion1?.setResume) {
|
|
await Suggestion1.setResume(relatedResume1);
|
|
}
|
|
|
|
const relatedResume2 = await Resumes.findOne({
|
|
offset: Math.floor(Math.random() * (await Resumes.count())),
|
|
});
|
|
const Suggestion2 = await Suggestions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Suggestion2?.setResume) {
|
|
await Suggestion2.setResume(relatedResume2);
|
|
}
|
|
|
|
const relatedResume3 = await Resumes.findOne({
|
|
offset: Math.floor(Math.random() * (await Resumes.count())),
|
|
});
|
|
const Suggestion3 = await Suggestions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Suggestion3?.setResume) {
|
|
await Suggestion3.setResume(relatedResume3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await JobDescriptions.bulkCreate(JobDescriptionsData);
|
|
|
|
await Resumes.bulkCreate(ResumesData);
|
|
|
|
await Suggestions.bulkCreate(SuggestionsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateJobDescriptionWithUser(),
|
|
|
|
await associateResumeWithUser(),
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateSuggestionWithResume(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('job_descriptions', null, {});
|
|
|
|
await queryInterface.bulkDelete('resumes', null, {});
|
|
|
|
await queryInterface.bulkDelete('suggestions', null, {});
|
|
},
|
|
};
|