@primocaredentgroup/elettromedicali 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.d.ts +0 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -28
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +4 -4
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/component.d.ts +165 -218
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/contracts.d.ts +9 -9
- package/dist/component/contracts.d.ts.map +1 -1
- package/dist/component/contracts.js +7 -13
- package/dist/component/contracts.js.map +1 -1
- package/dist/component/crons.d.ts.map +1 -1
- package/dist/component/crons.js +1 -2
- package/dist/component/crons.js.map +1 -1
- package/dist/component/dashboardStats.d.ts +8 -3
- package/dist/component/dashboardStats.d.ts.map +1 -1
- package/dist/component/dashboardStats.js +24 -39
- package/dist/component/dashboardStats.js.map +1 -1
- package/dist/component/dashboardStatsCache.d.ts +5 -11
- package/dist/component/dashboardStatsCache.d.ts.map +1 -1
- package/dist/component/dashboardStatsCache.js +12 -53
- package/dist/component/dashboardStatsCache.js.map +1 -1
- package/dist/component/deviceCategories.d.ts +22 -15
- package/dist/component/deviceCategories.d.ts.map +1 -1
- package/dist/component/deviceCategories.js +10 -4
- package/dist/component/deviceCategories.js.map +1 -1
- package/dist/component/deviceQuestions.d.ts +36 -27
- package/dist/component/deviceQuestions.d.ts.map +1 -1
- package/dist/component/deviceQuestions.js +22 -5
- package/dist/component/deviceQuestions.js.map +1 -1
- package/dist/component/deviceRepairHistory.d.ts +3 -3
- package/dist/component/deviceRepairHistory.js +1 -1
- package/dist/component/deviceRepairHistory.js.map +1 -1
- package/dist/component/deviceStatus.d.ts +8 -57
- package/dist/component/deviceStatus.d.ts.map +1 -1
- package/dist/component/deviceStatus.js +32 -30
- package/dist/component/deviceStatus.js.map +1 -1
- package/dist/component/devices.d.ts +39 -22
- package/dist/component/devices.d.ts.map +1 -1
- package/dist/component/devices.js +85 -96
- package/dist/component/devices.js.map +1 -1
- package/dist/component/emailHelpers.d.ts +10 -3
- package/dist/component/emailHelpers.d.ts.map +1 -1
- package/dist/component/emailHelpers.js +9 -20
- package/dist/component/emailHelpers.js.map +1 -1
- package/dist/component/emails.d.ts +5 -5
- package/dist/component/emails.js +2 -2
- package/dist/component/emails.js.map +1 -1
- package/dist/component/http.d.ts.map +1 -1
- package/dist/component/http.js +3 -108
- package/dist/component/http.js.map +1 -1
- package/dist/component/migrationHelpers.d.ts +29 -0
- package/dist/component/migrationHelpers.d.ts.map +1 -0
- package/dist/component/migrationHelpers.js +84 -0
- package/dist/component/migrationHelpers.js.map +1 -0
- package/dist/component/roles.d.ts +1 -0
- package/dist/component/roles.d.ts.map +1 -1
- package/dist/component/roles.js +5 -6
- package/dist/component/roles.js.map +1 -1
- package/dist/component/schema.d.ts +69 -150
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +35 -88
- package/dist/component/schema.js.map +1 -1
- package/dist/component/slaMonitoring.d.ts +16 -30
- package/dist/component/slaMonitoring.d.ts.map +1 -1
- package/dist/component/slaMonitoring.js +48 -99
- package/dist/component/slaMonitoring.js.map +1 -1
- package/dist/component/spareParts.d.ts +11 -48
- package/dist/component/spareParts.d.ts.map +1 -1
- package/dist/component/spareParts.js +41 -11
- package/dist/component/spareParts.js.map +1 -1
- package/dist/component/suppliers.d.ts +38 -19
- package/dist/component/suppliers.d.ts.map +1 -1
- package/dist/component/suppliers.js +63 -44
- package/dist/component/suppliers.js.map +1 -1
- package/dist/component/ticketComments.d.ts +18 -12
- package/dist/component/ticketComments.d.ts.map +1 -1
- package/dist/component/ticketComments.js +28 -59
- package/dist/component/ticketComments.js.map +1 -1
- package/dist/component/ticketDeviceData.d.ts +63 -0
- package/dist/component/ticketDeviceData.d.ts.map +1 -0
- package/dist/component/ticketDeviceData.js +103 -0
- package/dist/component/ticketDeviceData.js.map +1 -0
- package/dist/component/ticketExport.d.ts +22 -40
- package/dist/component/ticketExport.d.ts.map +1 -1
- package/dist/component/ticketExport.js +43 -109
- package/dist/component/ticketExport.js.map +1 -1
- package/dist/component/ticketHistory.d.ts +4 -4
- package/dist/component/ticketHistory.d.ts.map +1 -1
- package/dist/component/ticketHistory.js +6 -9
- package/dist/component/ticketHistory.js.map +1 -1
- package/dist/component/ticketMacros.d.ts +19 -18
- package/dist/component/ticketMacros.d.ts.map +1 -1
- package/dist/component/ticketMacros.js +24 -30
- package/dist/component/ticketMacros.js.map +1 -1
- package/dist/component/ticketStatuses.d.ts +1 -0
- package/dist/component/ticketStatuses.d.ts.map +1 -1
- package/dist/component/ticketStatuses.js +5 -6
- package/dist/component/ticketStatuses.js.map +1 -1
- package/dist/component/ticketTriggers.d.ts +36 -16
- package/dist/component/ticketTriggers.d.ts.map +1 -1
- package/dist/component/ticketTriggers.js +115 -153
- package/dist/component/ticketTriggers.js.map +1 -1
- package/dist/component/userProfiles.d.ts +25 -120
- package/dist/component/userProfiles.d.ts.map +1 -1
- package/dist/component/userProfiles.js +73 -384
- package/dist/component/userProfiles.js.map +1 -1
- package/dist/test.d.ts +69 -150
- package/dist/test.d.ts.map +1 -1
- package/package.json +12 -3
- package/src/client/index.ts +2 -30
- package/src/component/_generated/api.ts +4 -4
- package/src/component/_generated/component.ts +228 -350
- package/src/component/contracts.ts +7 -14
- package/src/component/crons.ts +2 -7
- package/src/component/dashboardStats.ts +24 -41
- package/src/component/dashboardStatsCache.ts +12 -61
- package/src/component/deviceCategories.ts +12 -4
- package/src/component/deviceQuestions.ts +28 -5
- package/src/component/deviceRepairHistory.ts +1 -1
- package/src/component/deviceStatus.ts +43 -45
- package/src/component/devices.ts +87 -106
- package/src/component/emailHelpers.ts +9 -19
- package/src/component/emails.ts +2 -2
- package/src/component/http.ts +3 -108
- package/src/component/migrationHelpers.ts +96 -0
- package/src/component/roles.ts +5 -6
- package/src/component/schema.ts +35 -93
- package/src/component/slaMonitoring.ts +52 -107
- package/src/component/spareParts.ts +46 -12
- package/src/component/suppliers.ts +71 -48
- package/src/component/ticketComments.ts +28 -71
- package/src/component/ticketDeviceData.ts +113 -0
- package/src/component/ticketExport.ts +52 -137
- package/src/component/ticketHistory.ts +6 -9
- package/src/component/ticketMacros.ts +25 -37
- package/src/component/ticketStatuses.ts +5 -6
- package/src/component/ticketTriggers.ts +121 -217
- package/src/component/userProfiles.ts +67 -451
- package/dist/component/clinics.d.ts +0 -103
- package/dist/component/clinics.d.ts.map +0 -1
- package/dist/component/clinics.js +0 -126
- package/dist/component/clinics.js.map +0 -1
- package/dist/component/maintenanceTasks.d.ts +0 -733
- package/dist/component/maintenanceTasks.d.ts.map +0 -1
- package/dist/component/maintenanceTasks.js +0 -937
- package/dist/component/maintenanceTasks.js.map +0 -1
- package/src/component/clinics.ts +0 -136
- package/src/component/maintenanceTasks.ts +0 -1003
|
@@ -73,7 +73,7 @@ export const createTrigger = mutation({
|
|
|
73
73
|
sendNotification: v.optional(v.object({
|
|
74
74
|
recipients: v.array(v.object({
|
|
75
75
|
type: v.union(v.literal('admin'), v.literal('supplier'), v.literal('ticket_creator'), v.literal('ticket_assignee'), v.literal('specific_user'), v.literal('specific_supplier')),
|
|
76
|
-
userId: v.optional(v.
|
|
76
|
+
userId: v.optional(v.string()),
|
|
77
77
|
supplierId: v.optional(v.id('suppliers')),
|
|
78
78
|
})),
|
|
79
79
|
message: v.string(),
|
|
@@ -163,7 +163,7 @@ export const updateTrigger = mutation({
|
|
|
163
163
|
sendNotification: v.optional(v.object({
|
|
164
164
|
recipients: v.array(v.object({
|
|
165
165
|
type: v.union(v.literal('admin'), v.literal('supplier'), v.literal('ticket_creator'), v.literal('ticket_assignee'), v.literal('specific_user'), v.literal('specific_supplier')),
|
|
166
|
-
userId: v.optional(v.
|
|
166
|
+
userId: v.optional(v.string()),
|
|
167
167
|
supplierId: v.optional(v.id('suppliers')),
|
|
168
168
|
})),
|
|
169
169
|
message: v.string(),
|
|
@@ -259,17 +259,27 @@ export const reorderTriggers = mutation({
|
|
|
259
259
|
});
|
|
260
260
|
export const executeTriggers = mutation({
|
|
261
261
|
args: {
|
|
262
|
-
ticketId: v.
|
|
262
|
+
ticketId: v.string(),
|
|
263
|
+
ticketData: v.object({
|
|
264
|
+
status: v.string(),
|
|
265
|
+
priority: v.optional(v.string()),
|
|
266
|
+
supplierId: v.optional(v.string()),
|
|
267
|
+
clinicId: v.optional(v.string()),
|
|
268
|
+
customFields: v.optional(v.any()),
|
|
269
|
+
notes: v.optional(v.string()),
|
|
270
|
+
}),
|
|
271
|
+
deviceData: v.optional(v.object({
|
|
272
|
+
category: v.optional(v.string()),
|
|
273
|
+
brand: v.optional(v.string()),
|
|
274
|
+
model: v.optional(v.string()),
|
|
275
|
+
})),
|
|
263
276
|
triggerOn: v.union(v.literal('create'), v.literal('status_change'), v.literal('update'), v.literal('sla_warning'), v.literal('sla_breach')),
|
|
264
277
|
oldStatus: v.optional(v.string()),
|
|
278
|
+
clinicRegion: v.optional(v.string()),
|
|
265
279
|
},
|
|
266
280
|
handler: async (ctx, args) => {
|
|
267
|
-
const ticket =
|
|
268
|
-
|
|
269
|
-
throw new Error('Ticket not found');
|
|
270
|
-
}
|
|
271
|
-
const device = ticket.deviceId ? await ctx.db.get(ticket.deviceId) : null;
|
|
272
|
-
const clinic = await ctx.db.get(ticket.clinicId);
|
|
281
|
+
const ticket = args.ticketData;
|
|
282
|
+
const device = args.deviceData || null;
|
|
273
283
|
const triggers = await ctx.db
|
|
274
284
|
.query('ticket_triggers')
|
|
275
285
|
.withIndex('by_isActive', (q) => q.eq('isActive', true))
|
|
@@ -283,39 +293,31 @@ export const executeTriggers = mutation({
|
|
|
283
293
|
result = value === args.triggerOn;
|
|
284
294
|
break;
|
|
285
295
|
case 'status':
|
|
286
|
-
|
|
287
|
-
result = statusValues.includes(ticket.status);
|
|
296
|
+
result = (Array.isArray(value) ? value : [value]).includes(ticket.status);
|
|
288
297
|
break;
|
|
289
298
|
case 'category':
|
|
290
|
-
|
|
291
|
-
result = device ? categoryValues.includes(device.category) : false;
|
|
299
|
+
result = device ? (Array.isArray(value) ? value : [value]).includes(device.category) : false;
|
|
292
300
|
break;
|
|
293
301
|
case 'brand':
|
|
294
|
-
|
|
295
|
-
result = device ? brandValues.includes(device.brand) : false;
|
|
302
|
+
result = device ? (Array.isArray(value) ? value : [value]).includes(device.brand) : false;
|
|
296
303
|
break;
|
|
297
304
|
case 'model':
|
|
298
|
-
|
|
299
|
-
result = device ? modelValues.includes(device.model) : false;
|
|
305
|
+
result = device ? (Array.isArray(value) ? value : [value]).includes(device.model) : false;
|
|
300
306
|
break;
|
|
301
307
|
case 'region':
|
|
302
|
-
|
|
303
|
-
const clinicRegion = clinic?.region;
|
|
304
|
-
result = clinicRegion ? regionValues.includes(clinicRegion) : false;
|
|
308
|
+
result = args.clinicRegion ? (Array.isArray(value) ? value : [value]).includes(args.clinicRegion) : false;
|
|
305
309
|
break;
|
|
306
310
|
case 'priority':
|
|
307
|
-
|
|
308
|
-
result = priorityValues.includes(ticket.priority);
|
|
311
|
+
result = (Array.isArray(value) ? value : [value]).includes(ticket.priority);
|
|
309
312
|
break;
|
|
310
|
-
case 'custom_field':
|
|
313
|
+
case 'custom_field': {
|
|
311
314
|
const { customFieldId, customFieldOperator } = condition;
|
|
312
315
|
if (!customFieldId) {
|
|
313
316
|
result = true;
|
|
314
317
|
break;
|
|
315
318
|
}
|
|
316
319
|
const fieldValue = ticket.customFields?.[customFieldId];
|
|
317
|
-
|
|
318
|
-
switch (operator) {
|
|
320
|
+
switch (customFieldOperator || 'equals') {
|
|
319
321
|
case 'equals':
|
|
320
322
|
result = fieldValue === value;
|
|
321
323
|
break;
|
|
@@ -337,10 +339,10 @@ export const executeTriggers = mutation({
|
|
|
337
339
|
case 'is_not_empty':
|
|
338
340
|
result = fieldValue !== undefined && fieldValue !== null && fieldValue !== '';
|
|
339
341
|
break;
|
|
340
|
-
default:
|
|
341
|
-
result = true;
|
|
342
|
+
default: result = true;
|
|
342
343
|
}
|
|
343
344
|
break;
|
|
345
|
+
}
|
|
344
346
|
default:
|
|
345
347
|
result = true;
|
|
346
348
|
}
|
|
@@ -356,177 +358,149 @@ export const executeTriggers = mutation({
|
|
|
356
358
|
let currentGroup = 0;
|
|
357
359
|
for (let i = 0; i < conditions.length; i++) {
|
|
358
360
|
andGroups[currentGroup].push(results[i]);
|
|
359
|
-
if (i < conditions.length - 1) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
currentGroup++;
|
|
363
|
-
andGroups[currentGroup] = [];
|
|
364
|
-
}
|
|
361
|
+
if (i < conditions.length - 1 && (conditions[i].nextOperator || 'AND') === 'OR') {
|
|
362
|
+
currentGroup++;
|
|
363
|
+
andGroups[currentGroup] = [];
|
|
365
364
|
}
|
|
366
365
|
}
|
|
367
|
-
|
|
368
|
-
return groupResults.some(r => r);
|
|
366
|
+
return andGroups.map(group => group.every(r => r)).some(r => r);
|
|
369
367
|
};
|
|
368
|
+
const allActions = [];
|
|
369
|
+
let currentStatus = ticket.status;
|
|
370
|
+
let currentNotes = ticket.notes || '';
|
|
370
371
|
for (const trigger of sortedTriggers) {
|
|
371
372
|
const triggerConditions = trigger.conditions;
|
|
372
|
-
if (triggerConditions.triggerOn && triggerConditions.triggerOn !== args.triggerOn)
|
|
373
|
+
if (triggerConditions.triggerOn && triggerConditions.triggerOn !== args.triggerOn)
|
|
373
374
|
continue;
|
|
374
|
-
|
|
375
|
+
let shouldExecute = false;
|
|
375
376
|
if (triggerConditions.conditionsList && triggerConditions.conditionsList.length > 0) {
|
|
376
|
-
|
|
377
|
-
if (!shouldExecute) {
|
|
378
|
-
continue;
|
|
379
|
-
}
|
|
377
|
+
shouldExecute = evaluateConditionsWithOperators(triggerConditions.conditionsList);
|
|
380
378
|
}
|
|
381
379
|
else {
|
|
382
|
-
if (trigger.conditions.triggerOn !== args.triggerOn)
|
|
380
|
+
if (trigger.conditions.triggerOn !== args.triggerOn)
|
|
383
381
|
continue;
|
|
384
|
-
}
|
|
385
382
|
const conditionLogic = trigger.conditions.conditionLogic || 'AND';
|
|
386
383
|
const conditionResults = [];
|
|
387
384
|
let categoryMatch = true;
|
|
388
385
|
if (!trigger.conditions.applyToAllCategories && device) {
|
|
389
|
-
if (!trigger.conditions.categories || !trigger.conditions.categories.includes(device.category))
|
|
386
|
+
if (!trigger.conditions.categories || !device.category || !trigger.conditions.categories.includes(device.category))
|
|
390
387
|
categoryMatch = false;
|
|
391
|
-
}
|
|
392
388
|
}
|
|
393
389
|
conditionResults.push(categoryMatch);
|
|
394
|
-
|
|
395
|
-
if (triggerConditions.brands && triggerConditions.brands.length > 0 && device) {
|
|
396
|
-
const brandOperator = triggerConditions.brandOperator || 'is';
|
|
390
|
+
if (triggerConditions.brands?.length > 0 && device) {
|
|
397
391
|
const brandInList = triggerConditions.brands.includes(device.brand);
|
|
398
|
-
|
|
399
|
-
brandMatch = brandInList;
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
brandMatch = !brandInList;
|
|
403
|
-
}
|
|
392
|
+
conditionResults.push((triggerConditions.brandOperator || 'is') === 'is' ? brandInList : !brandInList);
|
|
404
393
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
if (triggerConditions.models
|
|
408
|
-
const modelOperator = triggerConditions.modelOperator || 'is';
|
|
394
|
+
else
|
|
395
|
+
conditionResults.push(true);
|
|
396
|
+
if (triggerConditions.models?.length > 0 && device) {
|
|
409
397
|
const modelInList = triggerConditions.models.includes(device.model);
|
|
410
|
-
|
|
411
|
-
modelMatch = modelInList;
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
modelMatch = !modelInList;
|
|
415
|
-
}
|
|
398
|
+
conditionResults.push((triggerConditions.modelOperator || 'is') === 'is' ? modelInList : !modelInList);
|
|
416
399
|
}
|
|
417
|
-
|
|
400
|
+
else
|
|
401
|
+
conditionResults.push(true);
|
|
418
402
|
let regionMatch = true;
|
|
419
403
|
if (trigger.conditions.applyToAllRegions === false) {
|
|
420
|
-
|
|
421
|
-
if (!clinicRegion || !trigger.conditions.regions || !trigger.conditions.regions.includes(clinicRegion)) {
|
|
404
|
+
if (!args.clinicRegion || !trigger.conditions.regions?.includes(args.clinicRegion))
|
|
422
405
|
regionMatch = false;
|
|
423
|
-
}
|
|
424
406
|
}
|
|
425
407
|
conditionResults.push(regionMatch);
|
|
426
|
-
|
|
427
|
-
if (
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
if (statusOperator === 'is') {
|
|
431
|
-
statusMatch = statusInList;
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
statusMatch = !statusInList;
|
|
435
|
-
}
|
|
408
|
+
const statuses = trigger.conditions.statuses;
|
|
409
|
+
if (statuses && statuses.length > 0) {
|
|
410
|
+
const statusInList = statuses.includes(currentStatus);
|
|
411
|
+
conditionResults.push((trigger.conditions.statusOperator || 'is') === 'is' ? statusInList : !statusInList);
|
|
436
412
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
413
|
+
else
|
|
414
|
+
conditionResults.push(true);
|
|
415
|
+
const cfConditions = trigger.conditions.customFieldConditions;
|
|
416
|
+
if (cfConditions && cfConditions.length > 0) {
|
|
417
|
+
let cfMatch = true;
|
|
418
|
+
for (const cond of cfConditions) {
|
|
419
|
+
const fv = ticket.customFields?.[cond.fieldId];
|
|
420
|
+
let met = false;
|
|
421
|
+
switch (cond.operator) {
|
|
444
422
|
case 'equals':
|
|
445
|
-
|
|
423
|
+
met = fv === cond.value;
|
|
446
424
|
break;
|
|
447
425
|
case 'not_equals':
|
|
448
|
-
|
|
426
|
+
met = fv !== cond.value;
|
|
449
427
|
break;
|
|
450
428
|
case 'contains':
|
|
451
|
-
|
|
429
|
+
met = fv && String(fv).includes(String(cond.value));
|
|
452
430
|
break;
|
|
453
431
|
case 'greater_than':
|
|
454
|
-
|
|
432
|
+
met = fv && Number(fv) > Number(cond.value);
|
|
455
433
|
break;
|
|
456
434
|
case 'less_than':
|
|
457
|
-
|
|
435
|
+
met = fv && Number(fv) < Number(cond.value);
|
|
458
436
|
break;
|
|
459
437
|
case 'is_empty':
|
|
460
|
-
|
|
438
|
+
met = fv === undefined || fv === null || fv === '';
|
|
461
439
|
break;
|
|
462
440
|
case 'is_not_empty':
|
|
463
|
-
|
|
441
|
+
met = fv !== undefined && fv !== null && fv !== '';
|
|
464
442
|
break;
|
|
465
443
|
}
|
|
466
|
-
if (!
|
|
467
|
-
|
|
444
|
+
if (!met) {
|
|
445
|
+
cfMatch = false;
|
|
468
446
|
break;
|
|
469
447
|
}
|
|
470
448
|
}
|
|
449
|
+
conditionResults.push(cfMatch);
|
|
471
450
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
else {
|
|
478
|
-
shouldExecute = conditionResults.every(result => result === true);
|
|
479
|
-
}
|
|
480
|
-
if (!shouldExecute) {
|
|
481
|
-
continue;
|
|
482
|
-
}
|
|
451
|
+
else
|
|
452
|
+
conditionResults.push(true);
|
|
453
|
+
shouldExecute = conditionLogic === 'OR'
|
|
454
|
+
? conditionResults.some(r => r)
|
|
455
|
+
: conditionResults.every(r => r);
|
|
483
456
|
}
|
|
457
|
+
if (!shouldExecute)
|
|
458
|
+
continue;
|
|
459
|
+
const triggerActions = trigger.actions;
|
|
484
460
|
const updates = {};
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
updates.status = trigger.actions.changeStatus;
|
|
461
|
+
if (triggerActions.setPriority)
|
|
462
|
+
updates.priority = triggerActions.setPriority;
|
|
463
|
+
if (triggerActions.changeStatus) {
|
|
464
|
+
updates.status = triggerActions.changeStatus;
|
|
465
|
+
currentStatus = updates.status;
|
|
491
466
|
}
|
|
492
|
-
if (
|
|
493
|
-
updates.supplierId =
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
const priority = actions.setPriority || ticket.priority || 'medium';
|
|
467
|
+
if (triggerActions.assignSupplier)
|
|
468
|
+
updates.supplierId = triggerActions.assignSupplier;
|
|
469
|
+
if (triggerActions.applySlaRule && triggerActions.assignSupplier) {
|
|
470
|
+
const priority = triggerActions.setPriority || ticket.priority || 'medium';
|
|
497
471
|
const slaRule = await ctx.db
|
|
498
472
|
.query('sla_rules')
|
|
499
|
-
.withIndex('by_supplierId_priority', (q) => q.eq('supplierId',
|
|
473
|
+
.withIndex('by_supplierId_priority', (q) => q.eq('supplierId', triggerActions.assignSupplier).eq('priority', priority))
|
|
500
474
|
.first();
|
|
501
|
-
if (slaRule)
|
|
502
|
-
|
|
503
|
-
updates.slaDeadline = slaDeadline;
|
|
504
|
-
}
|
|
475
|
+
if (slaRule)
|
|
476
|
+
updates.slaDeadline = Date.now() + (slaRule.resolutionTimeHours * 60 * 60 * 1000);
|
|
505
477
|
}
|
|
506
|
-
else if (
|
|
507
|
-
|
|
508
|
-
updates.slaDeadline = slaDeadline;
|
|
478
|
+
else if (triggerActions.setSlaHours) {
|
|
479
|
+
updates.slaDeadline = Date.now() + (triggerActions.setSlaHours * 60 * 60 * 1000);
|
|
509
480
|
}
|
|
510
|
-
if (
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
updates.notes = currentNotes
|
|
481
|
+
if (triggerActions.addNote) {
|
|
482
|
+
const newNote = `[Trigger: ${trigger.name}] ${triggerActions.addNote}`;
|
|
483
|
+
currentNotes = currentNotes ? `${currentNotes}\n\n${newNote}` : newNote;
|
|
484
|
+
updates.notes = currentNotes;
|
|
514
485
|
}
|
|
515
486
|
if (Object.keys(updates).length > 0) {
|
|
516
|
-
|
|
517
|
-
|
|
487
|
+
allActions.push({
|
|
488
|
+
triggerId: trigger._id,
|
|
489
|
+
triggerName: trigger.name,
|
|
490
|
+
actions: updates,
|
|
491
|
+
});
|
|
518
492
|
try {
|
|
519
|
-
const
|
|
493
|
+
const desc = [];
|
|
520
494
|
if (updates.status)
|
|
521
|
-
|
|
495
|
+
desc.push(`Stato → ${updates.status}`);
|
|
522
496
|
if (updates.supplierId) {
|
|
523
497
|
const supplier = await ctx.db.get(updates.supplierId);
|
|
524
|
-
|
|
498
|
+
desc.push(`Assegnato a ${supplier?.name || 'fornitore'}`);
|
|
525
499
|
}
|
|
526
500
|
if (updates.priority)
|
|
527
|
-
|
|
501
|
+
desc.push(`Priorità → ${updates.priority}`);
|
|
528
502
|
if (updates.slaDeadline)
|
|
529
|
-
|
|
503
|
+
desc.push(`SLA impostato`);
|
|
530
504
|
await ctx.runMutation(api.ticketHistory.recordHistoryEvent, {
|
|
531
505
|
ticketId: args.ticketId,
|
|
532
506
|
eventType: 'trigger_executed',
|
|
@@ -534,9 +508,7 @@ export const executeTriggers = mutation({
|
|
|
534
508
|
triggerId: trigger._id,
|
|
535
509
|
oldValue: updates.status ? ticket.status : undefined,
|
|
536
510
|
newValue: updates.status,
|
|
537
|
-
|
|
538
|
-
newSupplierId: updates.supplierId,
|
|
539
|
-
notes: actionDescriptions.join(', '),
|
|
511
|
+
notes: desc.join(', '),
|
|
540
512
|
isSystemAction: true,
|
|
541
513
|
});
|
|
542
514
|
}
|
|
@@ -545,13 +517,14 @@ export const executeTriggers = mutation({
|
|
|
545
517
|
}
|
|
546
518
|
}
|
|
547
519
|
}
|
|
548
|
-
return { success: true };
|
|
520
|
+
return { success: true, actions: allActions };
|
|
549
521
|
},
|
|
550
522
|
});
|
|
551
523
|
export const checkAttachmentRequired = query({
|
|
552
524
|
args: {
|
|
553
525
|
deviceId: v.optional(v.id('devices')),
|
|
554
|
-
clinicId: v.optional(v.
|
|
526
|
+
clinicId: v.optional(v.string()),
|
|
527
|
+
clinicRegion: v.optional(v.string()),
|
|
555
528
|
status: v.optional(v.string()),
|
|
556
529
|
priority: v.optional(v.union(v.literal('low'), v.literal('medium'), v.literal('high'))),
|
|
557
530
|
customFields: v.optional(v.any()),
|
|
@@ -567,7 +540,6 @@ export const checkAttachmentRequired = query({
|
|
|
567
540
|
return { required: false, matchingTriggers: [] };
|
|
568
541
|
}
|
|
569
542
|
let device = null;
|
|
570
|
-
let clinic = null;
|
|
571
543
|
try {
|
|
572
544
|
if (args.deviceId) {
|
|
573
545
|
device = await ctx.db.get(args.deviceId);
|
|
@@ -576,14 +548,6 @@ export const checkAttachmentRequired = query({
|
|
|
576
548
|
catch (e) {
|
|
577
549
|
console.error('Error fetching device:', e);
|
|
578
550
|
}
|
|
579
|
-
try {
|
|
580
|
-
if (args.clinicId) {
|
|
581
|
-
clinic = await ctx.db.get(args.clinicId);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
catch (e) {
|
|
585
|
-
console.error('Error fetching clinic:', e);
|
|
586
|
-
}
|
|
587
551
|
const evaluateCondition = (condition) => {
|
|
588
552
|
const { type, negated, value } = condition;
|
|
589
553
|
let result = false;
|
|
@@ -609,8 +573,7 @@ export const checkAttachmentRequired = query({
|
|
|
609
573
|
break;
|
|
610
574
|
case 'region':
|
|
611
575
|
const regionValues = Array.isArray(value) ? value : [value];
|
|
612
|
-
|
|
613
|
-
result = clinicRegion ? regionValues.includes(clinicRegion) : false;
|
|
576
|
+
result = args.clinicRegion ? regionValues.includes(args.clinicRegion) : false;
|
|
614
577
|
break;
|
|
615
578
|
case 'priority':
|
|
616
579
|
const priorityValues = Array.isArray(value) ? value : [value];
|
|
@@ -707,8 +670,7 @@ export const checkAttachmentRequired = query({
|
|
|
707
670
|
}
|
|
708
671
|
let regionMatch = true;
|
|
709
672
|
if (triggerConditions.applyToAllRegions === false) {
|
|
710
|
-
|
|
711
|
-
if (!clinicRegion || !triggerConditions.regions || !triggerConditions.regions.includes(clinicRegion)) {
|
|
673
|
+
if (!args.clinicRegion || !triggerConditions.regions || !triggerConditions.regions.includes(args.clinicRegion)) {
|
|
712
674
|
regionMatch = false;
|
|
713
675
|
}
|
|
714
676
|
}
|