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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; // ════════════════════════════════════════════════════════════════ // PRODUCT CATALOG // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'crm_product_categories', timestamps: true }) export class CrmProductCategory extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ required: true }) categoryCode!: string; @Prop({ required: true }) categoryName!: string; @Prop({ type: MongooseSchema.Types.ObjectId }) parentCategoryId?: MongooseSchema.Types.ObjectId; @Prop({ default: true }) active!: boolean; @Prop({ default: 0 }) sortOrder!: number; } export const CrmProductCategorySchema = SchemaFactory.createForClass(CrmProductCategory); CrmProductCategorySchema.index( { tenantId: 1, categoryCode: 1 }, { unique: true }, ); @Schema({ collection: 'crm_products', timestamps: true }) export class CrmProduct extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ required: true }) productCode!: string; @Prop({ required: true }) productName!: string; @Prop() description?: string; @Prop({ type: MongooseSchema.Types.ObjectId }) categoryId?: MongooseSchema.Types.ObjectId; @Prop({ default: 'product', enum: ['product', 'service', 'subscription', 'bundle', 'addon', 'license'], }) productType!: string; @Prop({ default: 'INR' }) currency!: string; @Prop({ default: 0 }) unitPriceMinor!: number; @Prop() unit?: string; // per_unit, per_hour, per_month, per_year, flat, per_seat, per_user @Prop({ default: 0 }) taxPercentage!: number; @Prop() taxCode?: string; @Prop() hsnSacCode?: string; @Prop({ default: false }) discountable!: boolean; @Prop({ default: 0 }) maxDiscountPercentage!: number; @Prop({ default: true }) active!: boolean; @Prop() effectiveFrom?: Date; @Prop() effectiveTo?: Date; @Prop({ type: MongooseSchema.Types.Mixed, default: {} }) specifications?: Record<string, any>; @Prop({ type: [String], default: [] }) tags!: string[]; @Prop({ type: MongooseSchema.Types.Mixed, default: {} }) customFields!: Record<string, any>; } export const CrmProductSchema = SchemaFactory.createForClass(CrmProduct); CrmProductSchema.index({ tenantId: 1, productCode: 1 }, { unique: true }); CrmProductSchema.index({ tenantId: 1, categoryId: 1, active: 1 }); // ════════════════════════════════════════════════════════════════ // PRICE BOOKS // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'price_books', timestamps: true }) export class PriceBook extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ required: true }) priceBookName!: string; @Prop({ default: 'INR' }) currency!: string; @Prop({ default: false }) isDefault!: boolean; @Prop({ default: true }) active!: boolean; @Prop() description?: string; @Prop() effectiveFrom?: Date; @Prop() effectiveTo?: Date; @Prop({ type: [{ dimension: String, values: [String] }], default: [] }) applicableTo!: Array<{ dimension: string; values: string[] }>; } export const PriceBookSchema = SchemaFactory.createForClass(PriceBook); PriceBookSchema.index({ tenantId: 1, priceBookName: 1 }, { unique: true }); @Schema({ collection: 'price_book_entries', timestamps: true }) export class PriceBookEntry extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId, required: true }) priceBookId!: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId, required: true }) productId!: MongooseSchema.Types.ObjectId; @Prop({ default: 0 }) unitPriceMinor!: number; @Prop({ default: 'INR' }) currency!: string; @Prop({ default: 0 }) minQuantity!: number; @Prop({ default: 0 }) maxQuantity!: number; @Prop({ default: true }) active!: boolean; } export const PriceBookEntrySchema = SchemaFactory.createForClass(PriceBookEntry); PriceBookEntrySchema.index( { tenantId: 1, priceBookId: 1, productId: 1 }, { unique: true }, ); // ════════════════════════════════════════════════════════════════ // VOLUME / TIER PRICING // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'volume_tiers', timestamps: true }) export class VolumeTier extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId, required: true }) productId!: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId }) priceBookId?: MongooseSchema.Types.ObjectId; @Prop({ required: true }) minQuantity!: number; @Prop({ required: true }) maxQuantity!: number; @Prop({ required: true }) unitPriceMinor!: number; @Prop({ default: 0 }) discountPercentage!: number; @Prop({ default: true }) active!: boolean; } export const VolumeTierSchema = SchemaFactory.createForClass(VolumeTier); @Schema({ collection: 'discount_schedules', timestamps: true }) export class DiscountSchedule extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ required: true }) scheduleName!: string; @Prop({ default: 'volume', enum: ['volume', 'promotional', 'loyalty', 'seasonal', 'custom'], }) discountType!: string; @Prop({ type: [ { minQuantity: Number, maxQuantity: Number, percentage: Number, fixedMinor: Number, }, ], default: [], }) tiers!: Array<{ minQuantity: number; maxQuantity: number; percentage: number; fixedMinor: number; }>; @Prop() effectiveFrom?: Date; @Prop() effectiveTo?: Date; @Prop({ default: true }) active!: boolean; } export const DiscountScheduleSchema = SchemaFactory.createForClass(DiscountSchedule); // ════════════════════════════════════════════════════════════════ // LOSS REASONS // ════════════════════════════════════════════════════════════════ @Schema({ collection: 'loss_reasons', timestamps: true }) export class LossReason extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ required: true }) reasonCode!: string; @Prop({ required: true }) reasonName!: string; @Prop({ default: 'general', enum: [ 'price', 'product_fit', 'competitor', 'timing', 'budget', 'decision_maker', 'no_response', 'internal', 'general', 'custom', ], }) category!: string; @Prop({ default: true }) active!: boolean; } export const LossReasonSchema = SchemaFactory.createForClass(LossReason); LossReasonSchema.index({ tenantId: 1, reasonCode: 1 }, { unique: true }); |