187 lines
5.5 KiB
TypeScript
187 lines
5.5 KiB
TypeScript
import { ContractItemType, PrismaClient, Role } from '@prisma/client';
|
|
import * as bcrypt from 'bcrypt';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function seedAdmin(): Promise<void> {
|
|
const passwordHash = await bcrypt.hash(process.env.PASS_ADMIN_USER || '', 10);
|
|
|
|
const admin = await prisma.user.upsert({
|
|
where: { email: 'admin@iasis.com.br' },
|
|
update: {},
|
|
create: {
|
|
name: 'Admin',
|
|
email: 'admin@iasis.com.br',
|
|
password: passwordHash,
|
|
role: Role.ADMIN,
|
|
mustChangePassword: false,
|
|
},
|
|
});
|
|
|
|
console.log(`Admin: ${admin.email} (${admin.id})`);
|
|
}
|
|
|
|
async function seedSesMg(): Promise<void> {
|
|
const clientData = {
|
|
name: 'Secretaria de Estado de Saúde de Minas Gerais (SES-MG)',
|
|
document: '18.715.516/0001-88',
|
|
email: 'rafael.paiva@saude.mg.gov.br',
|
|
phone: '(31) 39152-0221',
|
|
contactName: 'Rafael Matos Paiva',
|
|
description: 'Cliente SESMG',
|
|
};
|
|
|
|
const existingClient = await prisma.client.findFirst({
|
|
where: { document: clientData.document },
|
|
});
|
|
|
|
const client = existingClient
|
|
? await prisma.client.update({ where: { id: existingClient.id }, data: clientData })
|
|
: await prisma.client.create({ data: clientData });
|
|
|
|
console.log(`Cliente: ${client.name} (${client.id})`);
|
|
|
|
const contractData = {
|
|
clientId: client.id,
|
|
name: 'Contrato SESMG',
|
|
code: 'CTSES001',
|
|
startDate: new Date('2026-04-01T00:00:00Z'),
|
|
};
|
|
|
|
const existingContract = await prisma.contract.findFirst({
|
|
where: { clientId: client.id, code: contractData.code },
|
|
});
|
|
|
|
const contract = existingContract
|
|
? await prisma.contract.update({ where: { id: existingContract.id }, data: contractData })
|
|
: await prisma.contract.create({ data: contractData });
|
|
|
|
console.log(`Contrato: ${contract.code} (${contract.id})`);
|
|
|
|
const items = [
|
|
{
|
|
code: 'I-01',
|
|
name: 'Licença SaaS',
|
|
description: 'Licença SaaS',
|
|
itemType: ContractItemType.SAAS_LICENSE,
|
|
totalUst: 5,
|
|
ustValue: 35000000,
|
|
timeboxDescoberta: null,
|
|
timeboxDesign: null,
|
|
timeboxArquitetura: null,
|
|
timeboxConstrucao: null,
|
|
},
|
|
{
|
|
code: 'I-02',
|
|
name: 'Desenvolvimento e implantação da tecnologia blockchain',
|
|
description: 'Desenvolvimento e implantação da tecnologia blockchain',
|
|
itemType: ContractItemType.UST,
|
|
totalUst: 50400,
|
|
ustValue: 533.33,
|
|
timeboxDescoberta: 40,
|
|
timeboxDesign: 40,
|
|
timeboxArquitetura: 40,
|
|
timeboxConstrucao: 40,
|
|
},
|
|
{
|
|
code: 'I-03',
|
|
name: 'Desenv/Manutenção (treinamento/consultoria pós-implantação)',
|
|
description: 'Desenvolvimento e Manutenção (treinamento/consultoria pós-implantação)',
|
|
itemType: ContractItemType.UST,
|
|
totalUst: 4800,
|
|
ustValue: 388.88,
|
|
timeboxDescoberta: 40,
|
|
timeboxDesign: 40,
|
|
timeboxArquitetura: 40,
|
|
timeboxConstrucao: 40,
|
|
},
|
|
{
|
|
code: 'I-04',
|
|
name: 'Desenvolvimento e Manutenção (manutenção, integrações e automações)',
|
|
description: 'Desenvolvimento e Manutenção (manutenção, integrações e automações)',
|
|
itemType: ContractItemType.UST,
|
|
totalUst: 15120,
|
|
ustValue: 533.33,
|
|
timeboxDescoberta: 40,
|
|
timeboxDesign: 40,
|
|
timeboxArquitetura: 40,
|
|
timeboxConstrucao: 80,
|
|
},
|
|
{
|
|
code: 'I-05',
|
|
name: 'Serviços Técnicos de Inteligência Artificial (IA)',
|
|
description: 'Serviços Técnicos de Inteligência Artificial (IA)',
|
|
itemType: ContractItemType.UST,
|
|
totalUst: 30240,
|
|
ustValue: 555.55,
|
|
timeboxDescoberta: 40,
|
|
timeboxDesign: 40,
|
|
timeboxArquitetura: 40,
|
|
timeboxConstrucao: 80,
|
|
},
|
|
];
|
|
|
|
for (const item of items) {
|
|
const saved = await prisma.contractItem.upsert({
|
|
where: { code_clientId: { code: item.code, clientId: client.id } },
|
|
update: { ...item, clientId: client.id },
|
|
create: { ...item, clientId: client.id },
|
|
});
|
|
console.log(` Item: ${saved.code} - ${saved.name}`);
|
|
}
|
|
|
|
const projectData = {
|
|
contractId: contract.id,
|
|
name: 'ISIS Platform',
|
|
code: 'ISIS-001',
|
|
description: 'Plataforma de interoperabilidade ISIS',
|
|
};
|
|
|
|
const existingProject = await prisma.project.findFirst({
|
|
where: { contractId: contract.id, code: projectData.code },
|
|
});
|
|
|
|
const project = existingProject
|
|
? await prisma.project.update({ where: { id: existingProject.id }, data: projectData })
|
|
: await prisma.project.create({ data: projectData });
|
|
|
|
console.log(`Projeto: ${project.code} (${project.id})`);
|
|
|
|
const profiles = [
|
|
'Especialista de Inteligência (Cientista de Dados)',
|
|
'Analista de Negócio/Processo',
|
|
'Especialista de Negócio (Saúde)',
|
|
'Especialista de Tecnologia / Arquiteto',
|
|
'Gerente de Projeto',
|
|
'Desenvolvedor / Engenheiro de Dados',
|
|
'Especialista de Infraestrutura',
|
|
'Scrum Master',
|
|
];
|
|
|
|
for (const name of profiles) {
|
|
const existing = await prisma.clientProfile.findFirst({
|
|
where: { clientId: client.id, name },
|
|
});
|
|
const profile = existing
|
|
? await prisma.clientProfile.update({ where: { id: existing.id }, data: { name } })
|
|
: await prisma.clientProfile.create({ data: { name, clientId: client.id } });
|
|
console.log(` Perfil: ${profile.name}`);
|
|
}
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
await seedAdmin();
|
|
await seedSesMg();
|
|
console.log('Seed concluído.');
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|
|
|