fix: scrip engine condition matching and ticket GET endpoint
- engine.ts: remove transaction_type-based scrip filtering. Now uses condition evaluator exclusively (matching by scrip.condition_type against transaction types was incorrect — 'OnResolve' ≠ 'StatusChange'). All non-disabled, queue-matching scrips are evaluated. - tickets.ts: fix GET /:id — replace broken Drizzle 'with' relation with manual CF join. Set up Drizzle relations needed for proper schema typing (customFieldValues → customFields).
This commit is contained in:
@@ -73,12 +73,21 @@ export function createTicketsRouter(db: Db): Hono {
|
||||
|
||||
const cfValues = await db.query.customFieldValues.findMany({
|
||||
where: eq(customFieldValues.ticket_id, id),
|
||||
with: {
|
||||
customField: true,
|
||||
},
|
||||
});
|
||||
|
||||
return c.json({ ...ticket, custom_fields: cfValues });
|
||||
const cfIds = [...new Set(cfValues.map(v => v.custom_field_id))];
|
||||
const cfRecords = cfIds.length > 0
|
||||
? await db.query.customFields.findMany({
|
||||
where: (fields, { inArray }) => inArray(fields.id, cfIds),
|
||||
})
|
||||
: [];
|
||||
const cfMap = new Map(cfRecords.map(cf => [cf.id, cf]));
|
||||
const customFieldsMapped = cfValues.map(v => ({
|
||||
...v,
|
||||
custom_field: cfMap.get(v.custom_field_id) ?? null,
|
||||
}));
|
||||
|
||||
return c.json({ ...ticket, custom_fields: customFieldsMapped });
|
||||
});
|
||||
|
||||
// PATCH /:id — update ticket
|
||||
|
||||
Reference in New Issue
Block a user