37885-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-01-27 22:30:05 +00:00

1040 lines
19 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Clients = db.clients;
const Services = db.services;
const Messages = db.messages;
const ClientsData = [
{
"name": "Oficina Solucao",
"contact_person": "Carlos Almeida",
"phone": "+55 11 98888-0001",
"email": "contato@oficinasolucao.com",
"address": "Rua das Flores 123, Sao Paulo SP",
"notes": "Key account with recurring monthly maintenance",
},
{
"name": "Mercado Central",
"contact_person": "Ana Ribeiro",
"phone": "+55 11 98888-0002",
"email": "ana.ribeiro@mercadocentral.com",
"address": "Av. Central 456, Sao Paulo SP",
"notes": "Large retail client, prefers morning visits",
},
{
"name": "Construtora NovaEra",
"contact_person": "Felipe Moura",
"phone": "+55 11 98888-0003",
"email": "felipe.moura@novaera.com",
"address": "Alameda das Industrias 78, Sao Paulo SP",
"notes": "Project-based engagements, billing on completion",
},
];
const ServicesData = [
{
"title": "Instalacao de Painel Eletrico",
"description": "Instalacao e configuracao do painel eletrico principal no site do cliente",
"status": "completed",
// type code here for "relation_one" field
// type code here for "relation_one" field
"scheduled_start": new Date('2026-02-05T09:00:00Z'),
"scheduled_end": new Date('2026-02-05T12:00:00Z'),
"price": 350.5,
// type code here for "images" field
// type code here for "files" field
"whatsapp_sent": true,
"technician_notes": "Bring spare fuses and insulating gloves",
},
{
"title": "Manutencao Ar Condicionado",
"description": "Revisao completa e limpeza de filtros de unidades de ar condicionado",
"status": "cancelled",
// type code here for "relation_one" field
// type code here for "relation_one" field
"scheduled_start": new Date('2026-02-06T08:00:00Z'),
"scheduled_end": new Date('2026-02-06T11:00:00Z'),
"price": 180.0,
// type code here for "images" field
// type code here for "files" field
"whatsapp_sent": false,
"technician_notes": "Replace filter in unit 3, test refrigerant levels",
},
{
"title": "Instalacao Iluminacao de Obra",
"description": "Montagem e teste de pontos de iluminacao temporaria",
"status": "in_progress",
// type code here for "relation_one" field
// type code here for "relation_one" field
"scheduled_start": new Date('2026-02-10T07:30:00Z'),
"scheduled_end": new Date('2026-02-10T10:30:00Z'),
"price": 500.0,
// type code here for "images" field
// type code here for "files" field
"whatsapp_sent": false,
"technician_notes": "Require site safety briefing before starting",
},
];
const MessagesData = [
{
"summary": "Service assigned notification",
"content": "O servico foi atribuido ao tecnico. Verifique os detalhes no dashboard.",
// type code here for "relation_one" field
// type code here for "relation_one" field
"sent_at": new Date('2026-02-01T08:00:00Z'),
"via_whatsapp": true,
},
{
"summary": "Client confirmation request",
"content": "Por favor confirme a disponibilidade para a visita agendada.",
// type code here for "relation_one" field
// type code here for "relation_one" field
"sent_at": new Date('2026-01-30T10:15:00Z'),
"via_whatsapp": true,
},
{
"summary": "Parts needed update",
"content": "Preciso de confirmação para substituicao de capacitor. Aprovado para prosseguir?",
// type code here for "relation_one" field
// type code here for "relation_one" field
"sent_at": new Date('2026-01-28T12:30:00Z'),
"via_whatsapp": true,
},
];
// Similar logic for "relation_many"
async function associateServiceWithClient() {
const relatedClient0 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Service0 = await Services.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Service0?.setClient)
{
await
Service0.
setClient(relatedClient0);
}
const relatedClient1 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Service1 = await Services.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Service1?.setClient)
{
await
Service1.
setClient(relatedClient1);
}
const relatedClient2 = await Clients.findOne({
offset: Math.floor(Math.random() * (await Clients.count())),
});
const Service2 = await Services.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Service2?.setClient)
{
await
Service2.
setClient(relatedClient2);
}
}
async function associateServiceWithTechnician() {
const relatedTechnician0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Service0 = await Services.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Service0?.setTechnician)
{
await
Service0.
setTechnician(relatedTechnician0);
}
const relatedTechnician1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Service1 = await Services.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Service1?.setTechnician)
{
await
Service1.
setTechnician(relatedTechnician1);
}
const relatedTechnician2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Service2 = await Services.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Service2?.setTechnician)
{
await
Service2.
setTechnician(relatedTechnician2);
}
}
async function associateMessageWithTo_user() {
const relatedTo_user0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message0 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Message0?.setTo_user)
{
await
Message0.
setTo_user(relatedTo_user0);
}
const relatedTo_user1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message1 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Message1?.setTo_user)
{
await
Message1.
setTo_user(relatedTo_user1);
}
const relatedTo_user2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Message2 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Message2?.setTo_user)
{
await
Message2.
setTo_user(relatedTo_user2);
}
}
async function associateMessageWithService() {
const relatedService0 = await Services.findOne({
offset: Math.floor(Math.random() * (await Services.count())),
});
const Message0 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Message0?.setService)
{
await
Message0.
setService(relatedService0);
}
const relatedService1 = await Services.findOne({
offset: Math.floor(Math.random() * (await Services.count())),
});
const Message1 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Message1?.setService)
{
await
Message1.
setService(relatedService1);
}
const relatedService2 = await Services.findOne({
offset: Math.floor(Math.random() * (await Services.count())),
});
const Message2 = await Messages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Message2?.setService)
{
await
Message2.
setService(relatedService2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Clients.bulkCreate(ClientsData);
await Services.bulkCreate(ServicesData);
await Messages.bulkCreate(MessagesData);
await Promise.all([
// Similar logic for "relation_many"
await associateServiceWithClient(),
await associateServiceWithTechnician(),
await associateMessageWithTo_user(),
await associateMessageWithService(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('clients', null, {});
await queryInterface.bulkDelete('services', null, {});
await queryInterface.bulkDelete('messages', null, {});
},
};