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 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; // ============================================================ // PAYMENT TRANSACTION & INTENT // ============================================================ @Schema({ timestamps: true, collection: 'payment_intents' }) export class PaymentIntent extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true }) amount: number; // minor units @Prop({ required: true, default: 'INR' }) currency: string; @Prop({ required: true, default: 'Stripe' }) providerName: string; // Stripe | Razorpay | Easebuzz @Prop({ required: true, default: 'PENDING', index: true }) status: string; // PENDING | SUCCEEDED | FAILED @Prop({ default: null }) providerIntentId: string; } export const PaymentIntentSchema = SchemaFactory.createForClass(PaymentIntent); @Schema({ timestamps: true, collection: 'payment_transactions' }) export class PaymentTransaction extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true, index: true }) invoiceId: string; @Prop({ required: true }) amount: number; @Prop({ required: true, default: 'INR' }) currency: string; @Prop({ required: true }) provider: string; // Stripe | Razorpay | Easebuzz @Prop({ required: true, unique: true, index: true }) transactionId: string; @Prop({ required: true, default: 'PENDING' }) status: string; // PENDING | SUCCESS | FAILED } export const PaymentTransactionSchema = SchemaFactory.createForClass(PaymentTransaction); // ============================================================ // BILLING INVOICES // ============================================================ @Schema({ timestamps: true, collection: 'billing_invoices' }) export class BillingInvoice extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true, unique: true, index: true }) invoiceNumber: string; // e.g. INV-2026-00001 @Prop({ required: true, default: 'draft', index: true }) status: string; // draft, issued, partially_paid, paid, overdue, void, refunded @Prop({ required: true }) subtotal: number; // minor units @Prop({ required: true, default: 0 }) tax: number; @Prop({ required: true, default: 0 }) discount: number; @Prop({ required: true }) total: number; // subtotal + tax - discount @Prop({ required: true, default: 'INR' }) currency: string; @Prop({ default: null }) pdfUrl: string; @Prop({ default: null }) issuedAt: Date; @Prop({ default: null }) paidAt: Date; } export const BillingInvoiceSchema = SchemaFactory.createForClass(BillingInvoice); // ============================================================ // COUPON ENGINE // ============================================================ @Schema({ timestamps: true, collection: 'coupons' }) export class Coupon extends Document { @Prop({ required: true, unique: true, index: true }) code: string; // e.g. SAVE20, LAUNCHFREE @Prop({ required: true, default: 'PERCENT' }) discountType: string; // PERCENT | FIXED @Prop({ required: true }) value: number; // e.g. 20 for percent, 500 for fixed (minor units) @Prop({ required: true }) expiresAt: Date; @Prop({ default: 0 }) maxRedemptions: number; @Prop({ default: 0 }) currentRedemptionsCount: number; @Prop({ default: true }) isActive: boolean; } export const CouponSchema = SchemaFactory.createForClass(Coupon); @Schema({ timestamps: true, collection: 'coupon_redemptions' }) export class CouponRedemption extends Document { @Prop({ required: true, index: true }) couponId: string; @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true }) discountApplied: number; // minor units @Prop({ default: null }) invoiceId: string; } export const CouponRedemptionSchema = SchemaFactory.createForClass(CouponRedemption); CouponRedemptionSchema.index({ couponId: 1, tenantId: 1 }, { unique: true }); |