279 lines
7.7 KiB
TypeScript
279 lines
7.7 KiB
TypeScript
import { PrismaClient } from '@prisma/client'
|
|
import { PrismaPg } from '@prisma/adapter-pg'
|
|
import { Pool } from 'pg'
|
|
import { ROLE_PERMISSIONS } from '../src/lib/auth/permissions'
|
|
|
|
const pool = new Pool({ connectionString: process.env.DATABASE_URL })
|
|
const adapter = new PrismaPg(pool)
|
|
const prisma = new PrismaClient({ adapter })
|
|
|
|
async function main() {
|
|
console.log('🌱 Starting database seed...')
|
|
|
|
// Create default roles
|
|
console.log('Creating roles...')
|
|
const roles = await Promise.all([
|
|
prisma.role.upsert({
|
|
where: { name: 'Admin' },
|
|
update: { permissions: ROLE_PERMISSIONS.Admin },
|
|
create: {
|
|
name: 'Admin',
|
|
description: 'Full system access with all permissions',
|
|
permissions: ROLE_PERMISSIONS.Admin,
|
|
},
|
|
}),
|
|
prisma.role.upsert({
|
|
where: { name: 'Manager' },
|
|
update: { permissions: ROLE_PERMISSIONS.Manager },
|
|
create: {
|
|
name: 'Manager',
|
|
description: 'Management access with task assignment and reporting',
|
|
permissions: ROLE_PERMISSIONS.Manager,
|
|
},
|
|
}),
|
|
prisma.role.upsert({
|
|
where: { name: 'Account Executive' },
|
|
update: { permissions: ROLE_PERMISSIONS['Account Executive'] },
|
|
create: {
|
|
name: 'Account Executive',
|
|
description: 'Client and task management access',
|
|
permissions: ROLE_PERMISSIONS['Account Executive'],
|
|
},
|
|
}),
|
|
prisma.role.upsert({
|
|
where: { name: 'Claims' },
|
|
update: { permissions: ROLE_PERMISSIONS.Claims },
|
|
create: {
|
|
name: 'Claims',
|
|
description: 'Claims department access',
|
|
permissions: ROLE_PERMISSIONS.Claims,
|
|
},
|
|
}),
|
|
])
|
|
console.log(`✅ Created ${roles.length} roles`)
|
|
|
|
// Create initial designations
|
|
console.log('Creating designations...')
|
|
const designations = await Promise.all([
|
|
prisma.designation.upsert({
|
|
where: { name: 'VIP' },
|
|
update: {},
|
|
create: {
|
|
name: 'VIP',
|
|
description: 'High-value clients requiring priority attention',
|
|
color: 'designation-purple',
|
|
displayOrder: 1,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.designation.upsert({
|
|
where: { name: 'Standard' },
|
|
update: {},
|
|
create: {
|
|
name: 'Standard',
|
|
description: 'Standard service level clients',
|
|
color: 'designation-blue',
|
|
displayOrder: 2,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.designation.upsert({
|
|
where: { name: 'New Client' },
|
|
update: {},
|
|
create: {
|
|
name: 'New Client',
|
|
description: 'Recently onboarded clients',
|
|
color: 'designation-green',
|
|
displayOrder: 3,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.designation.upsert({
|
|
where: { name: 'At Risk' },
|
|
update: {},
|
|
create: {
|
|
name: 'At Risk',
|
|
description: 'Clients requiring special attention',
|
|
color: 'designation-red',
|
|
displayOrder: 4,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.designation.upsert({
|
|
where: { name: 'Commercial' },
|
|
update: {},
|
|
create: {
|
|
name: 'Commercial',
|
|
description: 'Commercial lines clients',
|
|
color: 'designation-orange',
|
|
displayOrder: 5,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.designation.upsert({
|
|
where: { name: 'Personal' },
|
|
update: {},
|
|
create: {
|
|
name: 'Personal',
|
|
description: 'Personal lines clients',
|
|
color: 'designation-teal',
|
|
displayOrder: 6,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
])
|
|
console.log(`✅ Created ${designations.length} designations`)
|
|
|
|
// Create sample task templates
|
|
console.log('Creating task templates...')
|
|
const templates = await Promise.all([
|
|
prisma.taskTemplate.create({
|
|
data: {
|
|
name: 'Initial Renewal Review',
|
|
description: 'Review policy details and prepare renewal documentation',
|
|
department: 'PERSONAL_LINES',
|
|
timing: 'PRE_RENEWAL',
|
|
daysOffset: -60,
|
|
defaultPriority: 'MEDIUM',
|
|
displayOrder: 1,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.taskTemplate.create({
|
|
data: {
|
|
name: 'Client Contact - Renewal Discussion',
|
|
description: 'Contact client to discuss renewal options and coverage needs',
|
|
department: 'PERSONAL_LINES',
|
|
timing: 'PRE_RENEWAL',
|
|
daysOffset: -45,
|
|
defaultPriority: 'HIGH',
|
|
displayOrder: 2,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.taskTemplate.create({
|
|
data: {
|
|
name: 'Quote Preparation',
|
|
description: 'Prepare and submit renewal quotes',
|
|
department: 'PERSONAL_LINES',
|
|
timing: 'PRE_RENEWAL',
|
|
daysOffset: -30,
|
|
defaultPriority: 'HIGH',
|
|
displayOrder: 3,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.taskTemplate.create({
|
|
data: {
|
|
name: 'Quote Review with Client',
|
|
description: 'Present quotes and review options with client',
|
|
department: 'PERSONAL_LINES',
|
|
timing: 'PRE_RENEWAL',
|
|
daysOffset: -21,
|
|
defaultPriority: 'HIGH',
|
|
displayOrder: 4,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.taskTemplate.create({
|
|
data: {
|
|
name: 'Finalize Renewal',
|
|
description: 'Process final renewal paperwork and bind coverage',
|
|
department: 'PERSONAL_LINES',
|
|
timing: 'PRE_RENEWAL',
|
|
daysOffset: -7,
|
|
defaultPriority: 'URGENT',
|
|
displayOrder: 5,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.taskTemplate.create({
|
|
data: {
|
|
name: 'Post-Renewal Follow-up',
|
|
description: 'Confirm client satisfaction and address any questions',
|
|
department: 'PERSONAL_LINES',
|
|
timing: 'POST_RENEWAL',
|
|
daysOffset: 7,
|
|
defaultPriority: 'LOW',
|
|
displayOrder: 6,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.taskTemplate.create({
|
|
data: {
|
|
name: 'Commercial Lines Review',
|
|
description: 'Comprehensive review of commercial policy coverage',
|
|
department: 'COMMERCIAL_LINES',
|
|
timing: 'PRE_RENEWAL',
|
|
daysOffset: -90,
|
|
defaultPriority: 'HIGH',
|
|
displayOrder: 7,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.taskTemplate.create({
|
|
data: {
|
|
name: 'Loss Run Analysis',
|
|
description: 'Review and analyze loss runs for renewal pricing',
|
|
department: 'COMMERCIAL_LINES',
|
|
timing: 'PRE_RENEWAL',
|
|
daysOffset: -75,
|
|
defaultPriority: 'MEDIUM',
|
|
displayOrder: 8,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
prisma.taskTemplate.create({
|
|
data: {
|
|
name: 'Claims Review',
|
|
description: 'Review open and recent claims for policy',
|
|
department: 'CLAIMS',
|
|
timing: 'PRE_RENEWAL',
|
|
daysOffset: -45,
|
|
defaultPriority: 'MEDIUM',
|
|
displayOrder: 9,
|
|
isActive: true,
|
|
},
|
|
}),
|
|
])
|
|
console.log(`✅ Created ${templates.length} task templates`)
|
|
|
|
// Create sync configuration
|
|
console.log('Creating sync configuration...')
|
|
await prisma.syncConfig.upsert({
|
|
where: { key: 'sync_schedule_cron' },
|
|
update: { value: '0 2 * * *' },
|
|
create: {
|
|
key: 'sync_schedule_cron',
|
|
value: '0 2 * * *', // Daily at 2 AM
|
|
},
|
|
})
|
|
await prisma.syncConfig.upsert({
|
|
where: { key: 'sync_enabled' },
|
|
update: { value: 'true' },
|
|
create: {
|
|
key: 'sync_enabled',
|
|
value: 'true',
|
|
},
|
|
})
|
|
await prisma.syncConfig.upsert({
|
|
where: { key: 'policy_expiration_months_ahead' },
|
|
update: { value: '24' },
|
|
create: {
|
|
key: 'policy_expiration_months_ahead',
|
|
value: '24',
|
|
},
|
|
})
|
|
console.log('✅ Created sync configuration')
|
|
|
|
console.log('🎉 Seed completed successfully!')
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error('❌ Seed failed:', e)
|
|
process.exit(1)
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect()
|
|
})
|