All files / src/domains/finance/schemas fiscal-period.schema.ts

0% Statements 0/24
0% Branches 0/36
100% Functions 0/0
0% Lines 0/20

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                                                                                                               
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ collection: 'finance_fiscal_years', timestamps: true })
export class FinanceFiscalYear 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 })
  yearName!: string; // e.g. "FY-2026"
 
  @Prop({ required: true })
  startDate!: Date;
 
  @Prop({ required: true })
  endDate!: Date;
 
  @Prop({ required: true, enum: ['open', 'closed'], default: 'open' })
  status!: string;
}
 
export const FinanceFiscalYearSchema = SchemaFactory.createForClass(FinanceFiscalYear);
FinanceFiscalYearSchema.index({ tenantId: 1, legalEntityId: 1, yearName: 1 }, { unique: true });
 
 
@Schema({ collection: 'finance_periods', timestamps: true })
export class FinancePeriod extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId!: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  fiscalYearId!: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  periodName!: string; // e.g. "2026-07"
 
  @Prop({ required: true })
  startDate!: Date;
 
  @Prop({ required: true })
  endDate!: Date;
 
  @Prop({
    required: true,
    enum: ['future', 'open', 'soft_closed', 'hard_closed', 'reopened', 'archived'],
    default: 'open'
  })
  status!: string;
}
 
export const FinancePeriodSchema = SchemaFactory.createForClass(FinancePeriod);
FinancePeriodSchema.index({ tenantId: 1, fiscalYearId: 1, periodName: 1 }, { unique: true });