Files
yara724-api/src/fanavaran/schema/fanavaran-audit-log.schema.ts

112 lines
3.1 KiB
TypeScript

import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { HydratedDocument, Types } from "mongoose";
import type { FanavaranClientKey } from "src/core/config/fanavaran-client.config";
export enum FanavaranAuditStep {
GET_APP_TOKEN = "GET_APP_TOKEN",
LOGIN = "LOGIN",
POLICY_INQUIRY = "POLICY_INQUIRY",
BUILD_PAYLOAD = "BUILD_PAYLOAD",
SUBMIT_CLAIM = "SUBMIT_CLAIM",
CREATE_OTHER_PERSON = "CREATE_OTHER_PERSON",
SUBMIT_DAMAGE_CASE = "SUBMIT_DAMAGE_CASE",
SUBMIT_ATTACHMENT = "SUBMIT_ATTACHMENT",
SUBMIT_EXPERTISE = "SUBMIT_EXPERTISE",
}
export enum FanavaranAuditStatus {
STARTED = "started",
SUCCESS = "success",
FAILURE = "failure",
}
export enum FanavaranAuditSource {
PREVIEW = "preview",
SUBMIT = "submit",
AUTO_SUBMIT = "auto_submit",
LEGACY_SUBMIT = "legacy_submit",
}
@Schema({ collection: "fanavaranAuditLogs", timestamps: true })
export class FanavaranAuditLog {
@Prop({ type: String, required: true, index: true })
trackingCode: string;
@Prop({ type: String, required: true, enum: FanavaranAuditStep, index: true })
step: FanavaranAuditStep;
@Prop({
type: String,
required: true,
enum: FanavaranAuditStatus,
index: true,
})
status: FanavaranAuditStatus;
@Prop({ type: String, required: true, index: true })
clientKey: FanavaranClientKey;
@Prop({
type: String,
required: true,
enum: FanavaranAuditSource,
index: true,
})
source: FanavaranAuditSource;
@Prop({ type: Types.ObjectId, required: false, index: true })
claimCaseId?: Types.ObjectId;
@Prop({ type: Types.ObjectId, required: false, index: true })
claimRequestId?: Types.ObjectId;
@Prop({ type: String, required: false })
requestUrl?: string;
@Prop({ type: String, required: false })
requestMethod?: string;
@Prop({ type: Number, required: false })
httpStatus?: number;
/** Sanitized outbound headers (secrets masked). */
@Prop({ type: Object, required: false })
requestHeaders?: Record<string, unknown>;
/** Outbound JSON/body (truncated; secrets masked). */
@Prop({ type: Object, required: false })
requestBody?: unknown;
/** Compact structured facts (ids, flags) — kept for filtering/dashboards. */
@Prop({ type: Object, required: false })
requestMeta?: Record<string, unknown>;
/** Sanitized inbound response headers. */
@Prop({ type: Object, required: false })
responseHeaders?: Record<string, unknown>;
/** Inbound response body (truncated). */
@Prop({ type: Object, required: false })
responseBody?: unknown;
/** Compact structured facts from the response. */
@Prop({ type: Object, required: false })
responseMeta?: Record<string, unknown>;
@Prop({ type: String, required: false })
errorMessage?: string;
@Prop({ type: Object, required: false })
errorDetails?: Record<string, unknown>;
@Prop({ type: Number, required: false })
durationMs?: number;
}
export type FanavaranAuditLogDocument = HydratedDocument<FanavaranAuditLog>;
export const FanavaranAuditLogSchema =
SchemaFactory.createForClass(FanavaranAuditLog);
FanavaranAuditLogSchema.index({ trackingCode: 1, createdAt: 1 });
FanavaranAuditLogSchema.index({ claimCaseId: 1, createdAt: 1 });