All files / src/domains/finance/schemas banking.schema.ts

0% Statements 0/40
0% Branches 0/53
100% Functions 0/0
0% Lines 0/34

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                                                                                                                                                                                               
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ collection: 'finance_bank_accounts', timestamps: true })
export class FinanceBankAccount extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId!: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  legalEntityId!: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  accountName!: string;
 
  @Prop({ required: true })
  accountNumberEncrypted!: string;
 
  @Prop({ required: true })
  accountNumberMasked!: string;
 
  @Prop({ required: true })
  routingNumber!: string;
 
  @Prop({ required: true })
  bankName!: string;
 
  @Prop({ default: 0 })
  balanceMinor!: number;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  ledgerAccountId!: MongooseSchema.Types.ObjectId;
 
  @Prop({ default: true })
  isActive!: boolean;
}
 
export const FinanceBankAccountSchema = SchemaFactory.createForClass(FinanceBankAccount);
FinanceBankAccountSchema.index({ tenantId: 1, accountNumberMasked: 1 }, { unique: true });
 
 
@Schema({ collection: 'bank_statements', timestamps: true })
export class BankStatement extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId!: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  bankAccountId!: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  statementDate!: Date;
 
  @Prop({ default: 0 })
  startBalanceMinor!: number;
 
  @Prop({ default: 0 })
  endBalanceMinor!: number;
 
  @Prop({ required: true, enum: ['draft', 'processed'], default: 'draft' })
  status!: string;
}
 
export const BankStatementSchema = SchemaFactory.createForClass(BankStatement);
 
 
@Schema({ collection: 'bank_transactions', timestamps: true })
export class BankTransaction extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId!: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  bankAccountId!: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId })
  bankStatementId?: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  transactionDate!: Date;
 
  @Prop({ default: 0 })
  amountMinor!: number;
 
  @Prop({ required: true })
  description!: string;
 
  @Prop()
  reference?: string;
 
  @Prop({ required: true, enum: ['unmatched', 'matched', 'matched_manually'], default: 'unmatched' })
  status!: string;
 
  @Prop({ type: MongooseSchema.Types.ObjectId })
  matchedJournalEntryId?: MongooseSchema.Types.ObjectId;
}
 
export const BankTransactionSchema = SchemaFactory.createForClass(BankTransaction);