forked from Shared/esg
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
|
import { HydratedDocument } from 'mongoose';
|
|
import { InquiryStatus } from '../../common/enums/inquiry-status.enum';
|
|
import { InquiryType } from '../../common/enums/inquiry-type.enum';
|
|
import { ProviderName } from '../../common/enums/provider-name.enum';
|
|
|
|
export type InquiryLogDocument = HydratedDocument<InquiryLog>;
|
|
|
|
/**
|
|
* MongoDB audit trail for every inquiry attempt.
|
|
*/
|
|
@Schema({ timestamps: { createdAt: true, updatedAt: false }, collection: 'inquiry_logs' })
|
|
export class InquiryLog {
|
|
@Prop({ required: true, enum: InquiryType })
|
|
inquiryType!: InquiryType;
|
|
|
|
@Prop({ required: true, enum: ProviderName })
|
|
provider!: ProviderName;
|
|
|
|
@Prop({ type: Object, required: true })
|
|
requestPayload!: Record<string, unknown>;
|
|
|
|
@Prop({ type: Object, required: true })
|
|
maskedRequest!: Record<string, unknown>;
|
|
|
|
@Prop({ type: Object })
|
|
responsePayload?: Record<string, unknown>;
|
|
|
|
@Prop({ required: true, enum: InquiryStatus })
|
|
status!: InquiryStatus;
|
|
|
|
@Prop({ required: true })
|
|
duration!: number;
|
|
|
|
@Prop({ required: true, index: true })
|
|
requestId!: string;
|
|
|
|
@Prop({ required: true, index: true })
|
|
trackingCode!: string;
|
|
|
|
@Prop({ type: Object })
|
|
error?: Record<string, unknown>;
|
|
|
|
createdAt?: Date;
|
|
}
|
|
|
|
export const InquiryLogSchema = SchemaFactory.createForClass(InquiryLog);
|
|
|
|
InquiryLogSchema.index({ createdAt: -1, provider: 1, inquiryType: 1, status: 1 });
|
|
InquiryLogSchema.index({ provider: 1, inquiryType: 1, createdAt: -1 });
|
|
InquiryLogSchema.index({ 'error.code': 1, createdAt: -1 });
|