UNPKG

@accounter/server

Version:
52 lines 1.74 kB
import { __decorate, __metadata } from "tslib"; import { Injectable, Scope } from 'graphql-modules'; import { sql } from '@pgtyped/runtime'; import { TenantAwareDBClient } from '../../app-providers/tenant-db-client.js'; export const insertAuditLog = sql ` INSERT INTO accounter_schema.audit_logs ( business_id, user_id, auth0_user_id, action, entity, entity_id, details, ip_address ) VALUES ($ownerId, $userId, $auth0UserId, $action, $entity, $entityId, $details::jsonb, $ipAddress); `; let AuditLogsProvider = class AuditLogsProvider { db; constructor(db) { this.db = db; } async log(event, executor) { const db = executor ?? this.db; await insertAuditLog.run({ ownerId: event.ownerId ?? null, userId: event.userId ?? null, auth0UserId: event.auth0UserId ?? null, action: event.action, entity: event.entity ?? null, entityId: event.entityId ?? null, details: event.details ? JSON.stringify(event.details) : null, ipAddress: event.ipAddress ?? null, }, db); } // Backward-compatibility wrapper while call sites migrate to the typed event API. async insertAuditLog(params) { if (!params.action) { throw new Error('Audit action is required'); } return this.log(params); } }; AuditLogsProvider = __decorate([ Injectable({ scope: Scope.Operation, global: true, }), __metadata("design:paramtypes", [TenantAwareDBClient]) ], AuditLogsProvider); export { AuditLogsProvider }; //# sourceMappingURL=audit-logs.provider.js.map