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 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; @Schema({ timestamps: true, collection: 'assets' }) export class Asset extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true, unique: true }) assetNumber: string; // e.g. "AST-000001" @Prop({ required: true }) assetName: string; @Prop({ default: null }) description?: string; @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'AssetCategory', required: true }) categoryId: MongooseSchema.Types.ObjectId; @Prop({ default: null }) serialNumber?: string; @Prop({ default: null }) inventoryItemId?: string; @Prop({ default: null }) inventorySerialId?: string; @Prop({ default: null }) goodsReceiptId?: string; @Prop({ default: null }) vendorBillId?: string; @Prop({ required: true, default: () => new Date() }) acquisitionDate: Date; @Prop({ default: null }) capitalizationDate?: Date; @Prop({ required: true, default: 0 }) purchaseCostMinor: number; // Purchase price in minor units @Prop({ required: true, default: 0 }) capitalizationCostMinor: number; // Cost after attributions @Prop({ required: true, default: 0 }) residualValueMinor: number; // Residual value floor @Prop({ required: true, default: 36 }) usefulLifeMonths: number; @Prop({ default: 'Straight Line' }) depreciationMethod: string; // 'Straight Line' | 'Written Down Value' @Prop({ required: true, default: 0 }) accumulatedDepreciationMinor: number; @Prop({ required: true, default: 0 }) currentBookValueMinor: number; // Net Book Value @Prop({ default: 'INR' }) currency: string; @Prop({ default: 'active', index: true }) status: string; // 'planned' | 'received' | 'capitalized' | 'assigned' | 'under_maintenance' | 'disposed' | 'missing' @Prop({ default: 'Good' }) condition: string; // 'New' | 'Good' | 'Fair' | 'Damaged' @Prop({ default: null }) employeeCustodianId?: string; @Prop({ default: null }) departmentId?: string; @Prop({ default: null }) costCenterId?: string; @Prop({ default: null }) locationId?: string; @Prop({ default: null }) nextMaintenanceAt?: Date; @Prop({ default: null }) nextVerificationAt?: Date; } export const AssetSchema = SchemaFactory.createForClass(Asset); AssetSchema.index({ tenantId: 1, assetNumber: 1 }, { unique: true }); AssetSchema.index({ tenantId: 1, status: 1 }); @Schema({ timestamps: true, collection: 'asset_components' }) export class AssetComponent extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Asset', required: true }) parentAssetId: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Asset', required: true }) childAssetId: MongooseSchema.Types.ObjectId; @Prop({ default: 0 }) allocatedCostMinor: number; } export const AssetComponentSchema = SchemaFactory.createForClass(AssetComponent); AssetComponentSchema.index({ tenantId: 1, parentAssetId: 1, childAssetId: 1 }, { unique: true }); |