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 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; // ════════════════════════════════════════════════════════════════ // COUNTRY // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_countries', timestamps: true }) export class Country extends Document { @Prop({ required: true, unique: true, uppercase: true }) isoAlpha2!: string; // IN, US, GB @Prop({ required: true, unique: true, uppercase: true }) isoAlpha3!: string; // IND, USA, GBR @Prop({ required: true, unique: true }) isoNumeric!: string; // 356, 840, 826 @Prop({ required: true }) countryName!: string; @Prop() officialName?: string; @Prop() nativeName?: string; @Prop() callingCode?: string; // +91 @Prop() tld?: string; // .in @Prop() flagEmoji?: string; @Prop() flagUrl?: string; @Prop() defaultCurrencyCode?: string; @Prop() defaultLanguageCode?: string; @Prop() defaultTimezone?: string; @Prop({ type: [String], default: [] }) timezones!: string[]; @Prop({ type: [String], default: [] }) spokenLanguages!: string[]; @Prop() continent?: string; @Prop() region?: string; // Southern Asia @Prop() subRegion?: string; @Prop() capitalCity?: string; @Prop({ default: false }) systemManaged!: boolean; @Prop({ default: true }) active!: boolean; } export const CountrySchema = SchemaFactory.createForClass(Country); CountrySchema.index({ isoAlpha2: 1 }, { unique: true }); CountrySchema.index({ isoAlpha3: 1 }, { unique: true }); CountrySchema.index({ active: 1 }); CountrySchema.index({ continent: 1, active: 1 }); // ════════════════════════════════════════════════════════════════ // ADMINISTRATIVE REGION (State/Province/Territory) // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_administrative_regions', timestamps: true }) export class AdministrativeRegion extends Document { @Prop({ required: true, index: true }) countryCode!: string; // isoAlpha2 @Prop({ required: true }) regionCode!: string; // IN-AP, IN-TG, IN-MH @Prop({ required: true }) regionName!: string; @Prop() nativeName?: string; @Prop({ required: true, enum: [ 'state', 'province', 'territory', 'union_territory', 'prefecture', 'county', 'emirate', 'oblast', 'district', ], }) regionType!: string; @Prop() isoCode?: string; // ISO 3166-2 @Prop() abbreviation?: string; @Prop() timezone?: string; @Prop() capital?: string; @Prop({ type: MongooseSchema.Types.Mixed }) attributes?: any; // GST state code for India etc @Prop({ default: true }) active!: boolean; } export const AdministrativeRegionSchema = SchemaFactory.createForClass(AdministrativeRegion); AdministrativeRegionSchema.index( { countryCode: 1, regionCode: 1 }, { unique: true }, ); AdministrativeRegionSchema.index({ countryCode: 1, active: 1 }); // ════════════════════════════════════════════════════════════════ // CITY // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_cities', timestamps: true }) export class City extends Document { @Prop({ required: true, index: true }) countryCode!: string; @Prop({ index: true }) regionCode?: string; @Prop({ required: true }) cityCode!: string; @Prop({ required: true }) cityName!: string; @Prop() nativeName?: string; @Prop({ enum: ['megacity', 'metropolitan', 'city', 'town', 'municipality'] }) cityType?: string; @Prop({ type: Number }) latitude?: number; @Prop({ type: Number }) longitude?: number; @Prop() timezone?: string; @Prop() population?: number; @Prop({ default: false }) isCapital!: boolean; @Prop({ default: true }) active!: boolean; } export const CitySchema = SchemaFactory.createForClass(City); CitySchema.index({ countryCode: 1, regionCode: 1, active: 1 }); CitySchema.index({ cityCode: 1, countryCode: 1 }, { unique: true }); CitySchema.index({ cityName: 'text' }); // ════════════════════════════════════════════════════════════════ // POSTAL / ZIP REGION (optional — for address validation) // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_postal_regions', timestamps: true }) export class PostalRegion extends Document { @Prop({ required: true }) countryCode!: string; @Prop({ required: true }) postalCode!: string; @Prop() cityCode?: string; @Prop() regionCode?: string; @Prop() localityName?: string; @Prop({ default: true }) active!: boolean; } export const PostalRegionSchema = SchemaFactory.createForClass(PostalRegion); PostalRegionSchema.index({ countryCode: 1, postalCode: 1 }, { unique: true }); PostalRegionSchema.index({ countryCode: 1, regionCode: 1 }); // ════════════════════════════════════════════════════════════════ // TIMEZONE REGISTRY // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'mdm_timezones', timestamps: true }) export class TimezoneDefinition extends Document { @Prop({ required: true, unique: true }) tzCode!: string; // Asia/Kolkata @Prop({ required: true }) displayName!: string; // India Standard Time (IST) @Prop({ required: true }) utcOffset!: string; // +05:30 @Prop({ required: true }) utcOffsetMinutes!: number; // 330 @Prop({ default: false }) hasDst!: boolean; @Prop() dstOffsetMinutes?: number; @Prop({ type: [String], default: [] }) countryCodes!: string[]; @Prop() abbreviation?: string; // IST, EST, PST @Prop({ default: true }) active!: boolean; } export const TimezoneDefinitionSchema = SchemaFactory.createForClass(TimezoneDefinition); TimezoneDefinitionSchema.index({ tzCode: 1 }, { unique: true }); TimezoneDefinitionSchema.index({ countryCodes: 1, active: 1 }); |