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 155 156 157 158 159 160 161 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; // ════════════════════════════════════════════════════════════════ // CUSTOM MASTER FIELD (runtime field schema for a custom master) // ════════════════════════════════════════════════════════════════ @Schema({ _id: false }) export class CustomMasterField { @Prop({ required: true }) fieldKey!: string; @Prop({ required: true }) fieldLabel!: string; @Prop({ required: true, enum: [ 'text', 'number', 'decimal', 'boolean', 'date', 'datetime', 'select', 'multiselect', 'parent_lookup', 'lookup', 'url', 'email', 'phone', 'file', 'json', ], }) fieldType!: string; @Prop({ default: false }) required!: boolean; @Prop({ default: true }) searchable!: boolean; @Prop({ default: true }) listVisible!: boolean; @Prop({ default: true }) detailVisible!: boolean; @Prop({ type: [String], default: [] }) selectOptions!: string[]; @Prop() lookupDefinitionKey?: string; // for lookup field type @Prop({ type: MongooseSchema.Types.Mixed }) validation?: any; @Prop({ type: MongooseSchema.Types.Mixed }) defaultValue?: any; @Prop({ default: 0 }) sortOrder!: number; } export const CustomMasterFieldSchema = SchemaFactory.createForClass(CustomMasterField); // ════════════════════════════════════════════════════════════════ // CUSTOM MASTER DEFINITION // Tenant or global admin creates a brand-new lookup master at runtime // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_custom_definitions', timestamps: true }) export class CustomMasterDefinition extends Document { @Prop({ required: true }) masterKey!: string; // salutation, skill_category, custom_grades @Prop({ required: true }) masterName!: string; @Prop() description?: string; @Prop() icon?: string; @Prop({ type: MongooseSchema.Types.ObjectId }) tenantId?: MongooseSchema.Types.ObjectId; // null = global @Prop({ required: true, enum: ['list', 'tree', 'lookup'] }) masterType!: string; // list = flat, tree = hierarchical @Prop({ default: false }) hierarchical!: boolean; @Prop({ default: 5 }) maxDepth!: number; @Prop({ type: [CustomMasterFieldSchema], default: [] }) fields!: CustomMasterField[]; @Prop({ default: false }) requiresApproval!: boolean; @Prop({ default: false }) versioningEnabled!: boolean; @Prop({ default: false }) effectiveDateSupport!: boolean; @Prop({ default: true }) apiExposed!: boolean; @Prop({ default: true }) mobileExposed!: boolean; @Prop({ default: false }) publicExposed!: boolean; @Prop({ required: true, enum: ['draft', 'published', 'archived'], default: 'draft', }) status!: string; @Prop({ type: MongooseSchema.Types.ObjectId }) createdBy?: MongooseSchema.Types.ObjectId; } export const CustomMasterDefinitionSchema = SchemaFactory.createForClass( CustomMasterDefinition, ); CustomMasterDefinitionSchema.index( { masterKey: 1, tenantId: 1 }, { unique: true, sparse: true }, ); CustomMasterDefinitionSchema.index({ status: 1, tenantId: 1 }); // ════════════════════════════════════════════════════════════════ // CUSTOM MASTER RECORD // Records for any custom master definition // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_custom_records', timestamps: true }) export class CustomMasterRecord extends Document { @Prop({ required: true }) masterKey!: string; @Prop({ required: true, type: MongooseSchema.Types.ObjectId }) definitionId!: MongooseSchema.Types.ObjectId; @Prop({ required: true }) recordCode!: string; @Prop({ required: true }) recordName!: string; @Prop() shortName?: string; @Prop() description?: string; @Prop({ type: MongooseSchema.Types.ObjectId }) parentRecordId?: MongooseSchema.Types.ObjectId; @Prop({ default: 0 }) depth!: number; @Prop({ type: [String], default: [] }) ancestorCodes!: string[]; @Prop({ type: MongooseSchema.Types.Mixed, default: {} }) fieldValues!: Record< string, any >; @Prop({ default: 0 }) sortOrder!: number; @Prop({ type: MongooseSchema.Types.ObjectId }) tenantId?: MongooseSchema.Types.ObjectId; @Prop({ default: true }) active!: boolean; @Prop({ required: true, enum: ['draft', 'published', 'archived'], default: 'published', }) status!: string; @Prop({ type: MongooseSchema.Types.ObjectId }) createdBy?: MongooseSchema.Types.ObjectId; } export const CustomMasterRecordSchema = SchemaFactory.createForClass(CustomMasterRecord); CustomMasterRecordSchema.index( { masterKey: 1, recordCode: 1, tenantId: 1 }, { unique: true, sparse: true }, ); CustomMasterRecordSchema.index({ masterKey: 1, tenantId: 1, status: 1, active: 1, }); CustomMasterRecordSchema.index({ parentRecordId: 1, masterKey: 1 }); // ════════════════════════════════════════════════════════════════ // CUSTOM MASTER LAYOUT // UI grid/form layout for the custom master list/detail view // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_custom_layouts', timestamps: true }) export class CustomMasterLayout extends Document { @Prop({ required: true, type: MongooseSchema.Types.ObjectId }) definitionId!: MongooseSchema.Types.ObjectId; @Prop({ required: true }) masterKey!: string; @Prop({ required: true, enum: ['list', 'form', 'detail', 'mobile'] }) layoutType!: string; @Prop({ type: MongooseSchema.Types.Mixed }) layoutConfig!: any; // column order, widths, groups @Prop({ type: MongooseSchema.Types.ObjectId }) tenantId?: MongooseSchema.Types.ObjectId; @Prop({ default: true }) active!: boolean; } export const CustomMasterLayoutSchema = SchemaFactory.createForClass(CustomMasterLayout); CustomMasterLayoutSchema.index( { masterKey: 1, layoutType: 1, tenantId: 1 }, { unique: true, sparse: true }, ); |