Internal ticketing app with CTI routing, severity levels, and n8n integration. Stack: Express + TypeScript + Prisma + PostgreSQL / React + Vite + Tailwind - JWT auth for users, API key auth for service accounts (Goddard/n8n) - CTI hierarchy (Category > Type > Item) for ticket routing - Severity 1-5, auto-close resolved tickets after 14 days - Gitea Actions CI/CD building separate server/client images - Production docker-compose.yml with Traefik integration Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
103 lines
2.9 KiB
TypeScript
103 lines
2.9 KiB
TypeScript
import { PrismaClient } from '@prisma/client'
|
|
import bcrypt from 'bcryptjs'
|
|
import crypto from 'crypto'
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
async function main() {
|
|
console.log('Seeding database...')
|
|
|
|
// Admin user
|
|
await prisma.user.upsert({
|
|
where: { username: 'admin' },
|
|
update: {},
|
|
create: {
|
|
username: 'admin',
|
|
email: 'admin@internal',
|
|
displayName: 'Admin',
|
|
passwordHash: await bcrypt.hash('admin123', 12),
|
|
role: 'ADMIN',
|
|
},
|
|
})
|
|
|
|
// Goddard — n8n service account
|
|
const apiKey = `sk_${crypto.randomBytes(32).toString('hex')}`
|
|
const goddard = await prisma.user.upsert({
|
|
where: { username: 'goddard' },
|
|
update: {},
|
|
create: {
|
|
username: 'goddard',
|
|
email: 'goddard@internal',
|
|
displayName: 'Goddard',
|
|
passwordHash: await bcrypt.hash(crypto.randomBytes(32).toString('hex'), 12),
|
|
role: 'SERVICE',
|
|
apiKey,
|
|
},
|
|
})
|
|
|
|
const existingGoddard = await prisma.user.findUnique({ where: { username: 'goddard' } })
|
|
console.log(`\nGoddard API key: ${existingGoddard?.apiKey ?? apiKey}`)
|
|
console.log('(This key is only displayed once on first seed — copy it now)\n')
|
|
|
|
// Sample CTI structure
|
|
const theWrightServer = await prisma.category.upsert({
|
|
where: { name: 'TheWrightServer' },
|
|
update: {},
|
|
create: { name: 'TheWrightServer' },
|
|
})
|
|
|
|
const homelab = await prisma.category.upsert({
|
|
where: { name: 'Homelab' },
|
|
update: {},
|
|
create: { name: 'Homelab' },
|
|
})
|
|
|
|
const automation = await prisma.type.upsert({
|
|
where: { categoryId_name: { categoryId: theWrightServer.id, name: 'Automation' } },
|
|
update: {},
|
|
create: { name: 'Automation', categoryId: theWrightServer.id },
|
|
})
|
|
|
|
const media = await prisma.type.upsert({
|
|
where: { categoryId_name: { categoryId: theWrightServer.id, name: 'Media' } },
|
|
update: {},
|
|
create: { name: 'Media', categoryId: theWrightServer.id },
|
|
})
|
|
|
|
const infrastructure = await prisma.type.upsert({
|
|
where: { categoryId_name: { categoryId: homelab.id, name: 'Infrastructure' } },
|
|
update: {},
|
|
create: { name: 'Infrastructure', categoryId: homelab.id },
|
|
})
|
|
|
|
await prisma.item.upsert({
|
|
where: { typeId_name: { typeId: automation.id, name: 'Backup' } },
|
|
update: {},
|
|
create: { name: 'Backup', typeId: automation.id },
|
|
})
|
|
|
|
await prisma.item.upsert({
|
|
where: { typeId_name: { typeId: automation.id, name: 'Sync' } },
|
|
update: {},
|
|
create: { name: 'Sync', typeId: automation.id },
|
|
})
|
|
|
|
await prisma.item.upsert({
|
|
where: { typeId_name: { typeId: media.id, name: 'Plex' } },
|
|
update: {},
|
|
create: { name: 'Plex', typeId: media.id },
|
|
})
|
|
|
|
await prisma.item.upsert({
|
|
where: { typeId_name: { typeId: infrastructure.id, name: 'Proxmox' } },
|
|
update: {},
|
|
create: { name: 'Proxmox', typeId: infrastructure.id },
|
|
})
|
|
|
|
console.log('Seed complete.')
|
|
}
|
|
|
|
main()
|
|
.catch((e) => { console.error(e); process.exit(1) })
|
|
.finally(() => prisma.$disconnect())
|