feat: onboard service desk as second CASAN project

This commit is contained in:
thanhnv
2026-07-10 17:00:35 +09:00
parent 040af64191
commit f8215cd2eb
20 changed files with 208 additions and 13 deletions
+26
View File
@@ -0,0 +1,26 @@
const PRIORITIES = new Set(['LOW', 'NORMAL', 'HIGH', 'CRITICAL']);
export function createTicket({ id, summary, priority = 'NORMAL', requestedAt }) {
if (!id || !summary?.trim() || !requestedAt || !PRIORITIES.has(priority)) {
throw new Error('invalid ticket input');
}
return { id, summary: summary.trim(), priority, requestedAt, status: 'OPEN', assignee: null, resolvedAt: null };
}
export function assignTicket(ticket, assignee) {
if (!assignee?.trim() || !['OPEN', 'ASSIGNED'].includes(ticket.status)) {
throw new Error('ticket cannot be assigned');
}
return { ...ticket, assignee: assignee.trim(), status: 'ASSIGNED' };
}
export function resolveTicket(ticket, resolvedAt) {
if (ticket.status !== 'ASSIGNED' || !resolvedAt) throw new Error('ticket cannot be resolved');
return { ...ticket, status: 'RESOLVED', resolvedAt };
}
export function isSlaBreached(ticket, now) {
const targetHours = ticket.priority === 'CRITICAL' ? 1 : ticket.priority === 'HIGH' ? 4 : 24;
const elapsed = new Date(now).getTime() - new Date(ticket.requestedAt).getTime();
return ticket.status !== 'RESOLVED' && elapsed > targetHours * 60 * 60 * 1000;
}