Files
edr-platform/apps/edr-passenger-api/src/common/audit.actions.ts

96 lines
3.8 KiB
TypeScript

/**
* The closed vocabulary for audit rows.
*
* `AuditLog.action` and `AuditLog.entityType` are plain `String` columns, so nothing at the
* database level stops a caller inventing `created` or `schedule_updated`. These two maps are
* the convention: uppercase, semantic, and imported rather than typed inline. The pre-existing
* rows use `CREATE`/`UPDATE`/`DELETE`/`VERIFY`, so those keep their meaning and the rest extend
* them — no historical row changes shape.
*/
export const AUDIT_ACTIONS = {
// ── CRUD ───────────────────────────────────────────────────────────────────
CREATE: 'CREATE',
UPDATE: 'UPDATE',
DELETE: 'DELETE',
/** Undo of a soft delete (train restore, seat undo-remove, ticket restore). */
RESTORE: 'RESTORE',
// ── Explicit state transitions ─────────────────────────────────────────────
/** A status column moved. Prefer this over UPDATE when status is the point of the change. */
STATUS_CHANGE: 'STATUS_CHANGE',
CANCEL: 'CANCEL',
// ── Seats & coaches ────────────────────────────────────────────────────────
BLOCK: 'BLOCK',
UNBLOCK: 'UNBLOCK',
ASSIGN: 'ASSIGN',
UNASSIGN: 'UNASSIGN',
// ── Charges & money ────────────────────────────────────────────────────────
WAIVE: 'WAIVE',
PAY: 'PAY',
REFUND: 'REFUND',
/** Re-sending a payment link — no state change, but it re-exposes a payment token. */
RESEND: 'RESEND',
// ── Gate ───────────────────────────────────────────────────────────────────
BOARD: 'BOARD',
BOARD_DENIED: 'BOARD_DENIED',
/**
* Retained for backward-compatible filtering of gate rows written before BOARD existed.
* New code uses BOARD / BOARD_DENIED.
*/
VERIFY: 'VERIFY',
// ── Bulk / sweeps ──────────────────────────────────────────────────────────
BULK_CREATE: 'BULK_CREATE',
BULK_UPDATE: 'BULK_UPDATE',
SYNC: 'SYNC',
IMPORT: 'IMPORT',
} as const;
export type AuditAction = (typeof AUDIT_ACTIONS)[keyof typeof AUDIT_ACTIONS];
/**
* Entity names as they appear in `AuditLog.entityType`. These mirror the Prisma model names so
* a reader can go from an audit row straight to the table, and they back the backoffice
* Audit Logs filter dropdown.
*/
export const AUDIT_ENTITIES = {
// Master data
Station: 'Station',
Train: 'Train',
Coach: 'Coach',
CoachType: 'CoachType',
Seat: 'Seat',
SeatClass: 'SeatClass',
Route: 'Route',
RouteStop: 'RouteStop',
RouteCoachTemplate: 'RouteCoachTemplate',
Schedule: 'Schedule',
ScheduleFare: 'ScheduleFare',
CoachAssignment: 'CoachAssignment',
// Finance / tariff
FareRule: 'FareRule',
RouteFareRule: 'RouteFareRule',
SegmentFareRule: 'SegmentFareRule',
Currency: 'Currency',
Payment: 'Payment',
PaymentMethod: 'PaymentMethod',
SupplementaryCharge: 'SupplementaryCharge',
ExcessBaggageCharge: 'ExcessBaggageCharge',
BaggageAllowance: 'BaggageAllowance',
// Operations
Ticket: 'Ticket',
Booking: 'Booking',
BookingReschedule: 'BookingReschedule',
ReschedulePolicy: 'ReschedulePolicy',
BookingUpgrade: 'BookingUpgrade',
UpgradePolicy: 'UpgradePolicy',
} as const;
export type AuditEntity = (typeof AUDIT_ENTITIES)[keyof typeof AUDIT_ENTITIES];