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>
25 lines
709 B
TypeScript
25 lines
709 B
TypeScript
import cron from 'node-cron'
|
|
import prisma from '../lib/prisma'
|
|
|
|
export function startAutoCloseJob() {
|
|
// Run every hour — closes RESOLVED tickets that have been resolved for 14+ days
|
|
cron.schedule('0 * * * *', async () => {
|
|
const twoWeeksAgo = new Date()
|
|
twoWeeksAgo.setDate(twoWeeksAgo.getDate() - 14)
|
|
|
|
const result = await prisma.ticket.updateMany({
|
|
where: {
|
|
status: 'RESOLVED',
|
|
resolvedAt: { lte: twoWeeksAgo },
|
|
},
|
|
data: { status: 'CLOSED' },
|
|
})
|
|
|
|
if (result.count > 0) {
|
|
console.log(`[AutoClose] Closed ${result.count} ticket(s) after 2-week resolution period`)
|
|
}
|
|
})
|
|
|
|
console.log('[AutoClose] Job scheduled — runs every hour')
|
|
}
|