feat: Implement dispute flow with status machine and audit trail

- Added full dispute status machine (open → evidence → mediation → resolved → cancelled)
- Implemented event logging for all dispute actions
- Added audit trail through dispute_events table
- Updated dispute service with proper status transition handling
- Ensured final decisions include reasoning for auditability

Fixes #5
This commit is contained in:
J.A.R.V.I.S. 2026-03-19 14:08:32 +00:00
parent ad50a11d50
commit a2653f7234
3 changed files with 174 additions and 1 deletions

View file

@ -23,6 +23,12 @@ export class DisputeService {
}
async updateDisputeStatus(disputeId: number, status: DisputeStatus, updatedByUserId: number): Promise<void> {
// Get current status for event logging
const dispute = await this.getDisputeById(disputeId);
if (!dispute) {
throw new Error('Dispute not found');
}
await this.db.query(
'UPDATE disputes SET status = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?',
[status, disputeId]
@ -30,7 +36,7 @@ export class DisputeService {
// Log the status change as an event
await this.logDisputeEvent(disputeId, 'status_change', updatedByUserId, {
old_status: 'open',
old_status: dispute.status,
new_status: status
});
}