234 lines
5.1 KiB
JavaScript
234 lines
5.1 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Appointments = db.appointments;
|
|
|
|
const Barbers = db.barbers;
|
|
|
|
const Services = db.services;
|
|
|
|
const AppointmentsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-11-01T10:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-01T11:00:00Z'),
|
|
|
|
status: 'canceled',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-11-02T12:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-02T12:30:00Z'),
|
|
|
|
status: 'pending',
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
start_time: new Date('2023-11-03T14:00:00Z'),
|
|
|
|
end_time: new Date('2023-11-03T15:30:00Z'),
|
|
|
|
status: 'pending',
|
|
},
|
|
];
|
|
|
|
const BarbersData = [
|
|
{
|
|
name: 'Michael Brown',
|
|
|
|
specialty: 'Haircut',
|
|
},
|
|
|
|
{
|
|
name: 'Emily Jones',
|
|
|
|
specialty: 'Shave',
|
|
},
|
|
|
|
{
|
|
name: 'David Wilson',
|
|
|
|
specialty: 'Beard Trim',
|
|
},
|
|
];
|
|
|
|
const ServicesData = [
|
|
{
|
|
name: 'Haircut',
|
|
|
|
price: 25,
|
|
|
|
description: 'A standard haircut service.',
|
|
},
|
|
|
|
{
|
|
name: 'Shave',
|
|
|
|
price: 15,
|
|
|
|
description: 'A clean shave service.',
|
|
},
|
|
|
|
{
|
|
name: 'Beard Trim',
|
|
|
|
price: 10,
|
|
|
|
description: 'A quick beard trim service.',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateAppointmentWithCustomer() {
|
|
const relatedCustomer0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Appointment0 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Appointment0?.setCustomer) {
|
|
await Appointment0.setCustomer(relatedCustomer0);
|
|
}
|
|
|
|
const relatedCustomer1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Appointment1 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Appointment1?.setCustomer) {
|
|
await Appointment1.setCustomer(relatedCustomer1);
|
|
}
|
|
|
|
const relatedCustomer2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Appointment2 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Appointment2?.setCustomer) {
|
|
await Appointment2.setCustomer(relatedCustomer2);
|
|
}
|
|
}
|
|
|
|
async function associateAppointmentWithService() {
|
|
const relatedService0 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Appointment0 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Appointment0?.setService) {
|
|
await Appointment0.setService(relatedService0);
|
|
}
|
|
|
|
const relatedService1 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Appointment1 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Appointment1?.setService) {
|
|
await Appointment1.setService(relatedService1);
|
|
}
|
|
|
|
const relatedService2 = await Services.findOne({
|
|
offset: Math.floor(Math.random() * (await Services.count())),
|
|
});
|
|
const Appointment2 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Appointment2?.setService) {
|
|
await Appointment2.setService(relatedService2);
|
|
}
|
|
}
|
|
|
|
async function associateAppointmentWithBarber() {
|
|
const relatedBarber0 = await Barbers.findOne({
|
|
offset: Math.floor(Math.random() * (await Barbers.count())),
|
|
});
|
|
const Appointment0 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Appointment0?.setBarber) {
|
|
await Appointment0.setBarber(relatedBarber0);
|
|
}
|
|
|
|
const relatedBarber1 = await Barbers.findOne({
|
|
offset: Math.floor(Math.random() * (await Barbers.count())),
|
|
});
|
|
const Appointment1 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Appointment1?.setBarber) {
|
|
await Appointment1.setBarber(relatedBarber1);
|
|
}
|
|
|
|
const relatedBarber2 = await Barbers.findOne({
|
|
offset: Math.floor(Math.random() * (await Barbers.count())),
|
|
});
|
|
const Appointment2 = await Appointments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Appointment2?.setBarber) {
|
|
await Appointment2.setBarber(relatedBarber2);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Appointments.bulkCreate(AppointmentsData);
|
|
|
|
await Barbers.bulkCreate(BarbersData);
|
|
|
|
await Services.bulkCreate(ServicesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateAppointmentWithCustomer(),
|
|
|
|
await associateAppointmentWithService(),
|
|
|
|
await associateAppointmentWithBarber(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('appointments', null, {});
|
|
|
|
await queryInterface.bulkDelete('barbers', null, {});
|
|
|
|
await queryInterface.bulkDelete('services', null, {});
|
|
},
|
|
};
|