DuOrigin v2 - React + NestJS + Prisma + EUDR API Integration
This commit is contained in:
104
prisma/seed.ts
Normal file
104
prisma/seed.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
import bcrypt from 'bcryptjs'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
async function main() {
|
||||
console.log('🌱 Seeding database...')
|
||||
|
||||
// Create admin user
|
||||
const adminPassword = await bcrypt.hash('admin123', 10)
|
||||
const admin = await prisma.user.upsert({
|
||||
where: { email: 'admin@duorigin.com' },
|
||||
update: {},
|
||||
create: {
|
||||
email: 'admin@duorigin.com',
|
||||
hashedPassword: adminPassword,
|
||||
fullName: 'Administrador',
|
||||
role: 'admin',
|
||||
isActive: true,
|
||||
},
|
||||
})
|
||||
console.log('✅ Admin user created:', admin.email)
|
||||
|
||||
// Create operator user
|
||||
const operatorPassword = await bcrypt.hash('operator123', 10)
|
||||
const operator = await prisma.user.upsert({
|
||||
where: { email: 'operador@duorigin.com' },
|
||||
update: {},
|
||||
create: {
|
||||
email: 'operador@duorigin.com',
|
||||
hashedPassword: operatorPassword,
|
||||
fullName: 'Operador Teste',
|
||||
role: 'operator',
|
||||
isActive: true,
|
||||
},
|
||||
})
|
||||
console.log('✅ Operator user created:', operator.email)
|
||||
|
||||
// Create sample company
|
||||
const company = await prisma.company.upsert({
|
||||
where: { cnpj: '12345678000190' },
|
||||
update: {},
|
||||
create: {
|
||||
name: 'Fazenda Modelo LTDA',
|
||||
cnpj: '12345678000190',
|
||||
country: 'BR',
|
||||
state: 'MT',
|
||||
city: 'Cuiabá',
|
||||
euOperatorId: 'EU-OP-BR-001',
|
||||
},
|
||||
})
|
||||
console.log('✅ Company created:', company.name)
|
||||
|
||||
// Create sample propriedade
|
||||
const propriedade = await prisma.propriedade.upsert({
|
||||
where: { cpfCnpj: '11122233344' },
|
||||
update: {},
|
||||
create: {
|
||||
name: 'Fazenda Santa Clara',
|
||||
cpfCnpj: '11122233344',
|
||||
companyId: company.id,
|
||||
state: 'MT',
|
||||
city: 'Sorriso',
|
||||
carCode: 'MT-5107008-001',
|
||||
},
|
||||
})
|
||||
console.log('✅ Propriedade created:', propriedade.name)
|
||||
|
||||
// Create sample avaliacao
|
||||
const avaliacao = await prisma.avaliacao.create({
|
||||
data: {
|
||||
name: 'Área de Soja - Talhão 1',
|
||||
propriedadeId: propriedade.id,
|
||||
areaHa: 150.5,
|
||||
biome: 'Cerrado',
|
||||
riskLevel: 'low',
|
||||
deforestationFlag: 'clean',
|
||||
latCenter: -12.5489,
|
||||
lonCenter: -55.7189,
|
||||
geojson: JSON.stringify({
|
||||
type: 'Polygon',
|
||||
coordinates: [[
|
||||
[-55.72, -12.54],
|
||||
[-55.71, -12.54],
|
||||
[-55.71, -12.55],
|
||||
[-55.72, -12.55],
|
||||
[-55.72, -12.54],
|
||||
]],
|
||||
}),
|
||||
},
|
||||
})
|
||||
console.log('✅ Avaliacao created:', avaliacao.name)
|
||||
|
||||
console.log('🎉 Seed completed!')
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error('❌ Seed error:', e)
|
||||
process.exit(1)
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect()
|
||||
})
|
||||
Reference in New Issue
Block a user