forked from Shared/esg
initial commit
This commit is contained in:
51
src/logging/schemas/inquiry-log.schema.ts
Normal file
51
src/logging/schemas/inquiry-log.schema.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
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 });
|
||||
Reference in New Issue
Block a user