Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; // ════════════════════════════════════════════════════════════════ // MDM IMPORT MAPPING (field mapping template for CSV/JSON imports) // ════════════════════════════════════════════════════════════════ @Schema({ _id: false }) export class MdmFieldMapping { @Prop({ required: true }) sourceColumn!: string; @Prop({ required: true }) targetField!: string; @Prop() transformExpression?: string; // e.g. 'toUpperCase', 'trim', 'lookup:countryCode' @Prop({ default: false }) required!: boolean; @Prop() defaultValue?: string; } export const MdmFieldMappingSchema = SchemaFactory.createForClass(MdmFieldMapping); @Schema({ collection: 'mdm_import_mappings', timestamps: true }) export class MdmImportMapping extends Document { @Prop({ required: true }) mappingCode!: string; @Prop({ required: true }) mappingName!: string; @Prop({ required: true }) definitionKey!: string; @Prop({ required: true, enum: ['csv', 'json', 'xlsx'] }) sourceFormat!: string; @Prop({ type: [MdmFieldMappingSchema], default: [] }) fieldMappings!: MdmFieldMapping[]; @Prop({ default: false }) skipHeader!: boolean; @Prop() delimiter?: string; @Prop() encoding?: string; @Prop({ type: MongooseSchema.Types.ObjectId }) tenantId?: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId }) createdBy?: MongooseSchema.Types.ObjectId; @Prop({ default: true }) active!: boolean; } export const MdmImportMappingSchema = SchemaFactory.createForClass(MdmImportMapping); MdmImportMappingSchema.index( { mappingCode: 1, definitionKey: 1, tenantId: 1 }, { unique: true, sparse: true }, ); // ════════════════════════════════════════════════════════════════ // MDM IMPORT JOB // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_import_jobs', timestamps: true }) export class MdmImportJob extends Document { @Prop({ required: true }) definitionKey!: string; @Prop({ required: true, enum: ['csv', 'json', 'xlsx'] }) sourceFormat!: string; @Prop() sourceFileName?: string; @Prop() sourceFileUrl?: string; @Prop({ type: MongooseSchema.Types.ObjectId }) importMappingId?: MongooseSchema.Types.ObjectId; @Prop({ required: true, enum: [ 'queued', 'validating', 'validated', 'importing', 'completed', 'partial', 'failed', 'cancelled', ], default: 'queued', }) status!: string; @Prop({ default: 0 }) totalRows!: number; @Prop({ default: 0 }) validRows!: number; @Prop({ default: 0 }) importedRows!: number; @Prop({ default: 0 }) skippedRows!: number; @Prop({ default: 0 }) failedRows!: number; @Prop({ default: 0 }) duplicateRows!: number; @Prop({ required: true, enum: ['create_only', 'update_only', 'create_or_update', 'skip_duplicate'], default: 'create_or_update', }) conflictStrategy!: string; @Prop({ default: false }) dryRun!: boolean; @Prop({ type: MongooseSchema.Types.ObjectId }) tenantId?: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId }) startedBy?: MongooseSchema.Types.ObjectId; @Prop() startedAt?: Date; @Prop() completedAt?: Date; @Prop({ type: MongooseSchema.Types.Mixed }) summary?: any; } export const MdmImportJobSchema = SchemaFactory.createForClass(MdmImportJob); MdmImportJobSchema.index({ definitionKey: 1, status: 1, tenantId: 1 }); MdmImportJobSchema.index({ startedBy: 1, status: 1 }); // ════════════════════════════════════════════════════════════════ // MDM IMPORT ROW (individual row result) // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_import_rows', timestamps: true }) export class MdmImportRow extends Document { @Prop({ required: true, type: MongooseSchema.Types.ObjectId, index: true }) importJobId!: MongooseSchema.Types.ObjectId; @Prop({ required: true }) rowNumber!: number; @Prop({ type: MongooseSchema.Types.Mixed }) rawData?: any; @Prop({ type: MongooseSchema.Types.Mixed }) parsedData?: any; @Prop({ required: true, enum: ['pending', 'valid', 'invalid', 'imported', 'skipped', 'failed'], default: 'pending', }) status!: string; @Prop({ type: [String], default: [] }) validationErrors!: string[]; @Prop({ type: MongooseSchema.Types.ObjectId }) createdRecordId?: MongooseSchema.Types.ObjectId; @Prop() errorMessage?: string; } export const MdmImportRowSchema = SchemaFactory.createForClass(MdmImportRow); MdmImportRowSchema.index({ importJobId: 1, rowNumber: 1 }); MdmImportRowSchema.index({ importJobId: 1, status: 1 }); // ════════════════════════════════════════════════════════════════ // MDM EXPORT JOB // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_export_jobs', timestamps: true }) export class MdmExportJob extends Document { @Prop({ required: true }) definitionKey!: string; @Prop({ required: true, enum: ['csv', 'json', 'xlsx'] }) exportFormat!: string; @Prop({ type: MongooseSchema.Types.Mixed }) filters?: any; @Prop({ type: [String], default: [] }) selectedFields!: string[]; @Prop({ required: true, enum: ['queued', 'processing', 'completed', 'failed', 'cancelled'], default: 'queued', }) status!: string; @Prop({ default: 0 }) totalRecords!: number; @Prop() fileUrl?: string; @Prop() fileSizeBytes?: number; @Prop({ type: MongooseSchema.Types.ObjectId }) tenantId?: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId }) requestedBy?: MongooseSchema.Types.ObjectId; @Prop() completedAt?: Date; @Prop() expiresAt?: Date; } export const MdmExportJobSchema = SchemaFactory.createForClass(MdmExportJob); MdmExportJobSchema.index({ definitionKey: 1, status: 1, tenantId: 1 }); MdmExportJobSchema.index({ requestedBy: 1, status: 1 }); MdmExportJobSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 }); // TTL auto-cleanup |