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 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; // ════════════════════════════════════════════════════════════════ // MASTER DATA FIELD DEFINITION (for custom masters) // ════════════════════════════════════════════════════════════════ @Schema({ _id: false }) export class MasterDataFieldDef { @Prop({ required: true }) fieldKey!: string; @Prop({ required: true }) fieldLabel!: string; @Prop({ required: true, enum: [ 'text', 'number', 'decimal', 'boolean', 'date', 'datetime', 'select', 'multiselect', 'parent_lookup', 'user', 'department', 'branch', 'country', 'currency', 'unit', 'file', 'url', ], }) fieldType!: string; @Prop({ default: false }) required!: boolean; @Prop({ default: false }) unique!: boolean; @Prop({ default: true }) searchable!: boolean; @Prop({ default: true }) exportable!: boolean; @Prop({ type: MongooseSchema.Types.Mixed }) validation?: any; @Prop({ type: [String], default: [] }) selectOptions!: string[]; @Prop({ default: 0 }) sortOrder!: number; @Prop({ default: true }) active!: boolean; } export const MasterDataFieldDefSchema = SchemaFactory.createForClass(MasterDataFieldDef); // ════════════════════════════════════════════════════════════════ // MASTER DATA DEFINITION // Defines the schema/type of a master data entity // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_definitions', timestamps: true }) export class MasterDataDefinition extends Document { @Prop({ required: true, unique: true }) definitionKey!: string; @Prop({ required: true }) definitionName!: string; @Prop() description?: string; @Prop({ required: true, enum: [ 'global', 'country', 'region', 'tenant', 'legal_entity', 'branch', 'department', 'module', ], }) scopeType!: string; @Prop({ default: false }) systemManaged!: boolean; @Prop({ default: true }) tenantEditable!: boolean; @Prop({ default: false }) requiresApproval!: boolean; @Prop({ default: false }) hierarchical!: boolean; @Prop({ default: 20 }) maxHierarchyDepth!: number; @Prop({ default: false }) effectiveDateSupport!: boolean; @Prop({ default: false }) versioningEnabled!: boolean; @Prop({ default: false }) duplicateDetectionEnabled!: boolean; @Prop({ type: [String], default: [] }) moduleKeys!: string[]; @Prop({ type: [String], default: [] }) countryRestrictions!: string[]; @Prop({ type: [MasterDataFieldDefSchema], default: [] }) fields!: MasterDataFieldDef[]; @Prop({ default: false }) apiExposed!: boolean; @Prop({ default: false }) mobileExposed!: boolean; @Prop({ default: false }) publicExposed!: boolean; @Prop({ default: false }) reportExposed!: boolean; @Prop({ required: true, enum: ['draft', 'published', 'archived'], default: 'draft', }) status!: string; @Prop({ type: MongooseSchema.Types.ObjectId }) createdBy?: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId }) updatedBy?: MongooseSchema.Types.ObjectId; @Prop() deletedAt?: Date; } export const MasterDataDefinitionSchema = SchemaFactory.createForClass(MasterDataDefinition); MasterDataDefinitionSchema.index({ definitionKey: 1 }, { unique: true }); MasterDataDefinitionSchema.index({ status: 1, systemManaged: 1 }); MasterDataDefinitionSchema.index({ moduleKeys: 1, status: 1 }); |