All files / src/platform/storage/schemas storage-hub.schema.ts

0% Statements 0/55
0% Branches 0/4
100% Functions 0/0
0% Lines 0/45

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                                                                                                                                                                                                                                                                   
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
 
@Schema({ timestamps: true, collection: 'storage_volumes' })
export class StorageVolume extends Document {
  @Prop({ required: true, unique: true })
  volumeId: string;
 
  @Prop({ required: true })
  name: string;
 
  @Prop({ required: true })
  rootPath: string; // Absolute VPS path, e.g. '/var/lib/bevision/volumes/vol1'
 
  @Prop({ required: true, default: 0 })
  capacityBytes: number;
 
  @Prop({ required: true, default: 0 })
  usedBytes: number;
 
  @Prop({ default: true })
  isActive: boolean;
 
  createdAt: Date;
  updatedAt: Date;
}
export const StorageVolumeSchema = SchemaFactory.createForClass(StorageVolume);
 
@Schema({ timestamps: true, collection: 'storage_allocations' })
export class StorageAllocation extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true, default: 0 })
  allocatedBytes: number;
 
  @Prop({ required: true, default: 0 })
  usedBytes: number;
 
  createdAt: Date;
  updatedAt: Date;
}
export const StorageAllocationSchema =
  SchemaFactory.createForClass(StorageAllocation);
StorageAllocationSchema.index({ tenantId: 1 }, { unique: true });
 
@Schema({ timestamps: true, collection: 'storage_objects' })
export class StorageObject extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true, unique: true, index: true })
  key: string; // Dynamic path key, e.g. 'tenants/{tenantId}/invoices/inv1.pdf'
 
  @Prop({ required: true })
  filename: string;
 
  @Prop({ required: true })
  volumeId: string;
 
  @Prop({ required: true })
  relativePath: string; // Relative to volume rootPath
 
  @Prop({ required: true })
  mimeType: string;
 
  @Prop({ required: true })
  sizeBytes: number;
 
  @Prop({ required: true })
  checksum: string; // SHA-256
 
  @Prop({ default: 1 })
  version: number;
 
  @Prop({ default: false })
  isDeleted: boolean;
 
  createdAt: Date;
  updatedAt: Date;
}
export const StorageObjectSchema = SchemaFactory.createForClass(StorageObject);
StorageObjectSchema.index({ tenantId: 1, key: 1 });
 
@Schema({ timestamps: true, collection: 'storage_object_versions' })
export class StorageObjectVersion extends Document {
  @Prop({ required: true, index: true })
  objectId: string;
 
  @Prop({ required: true })
  key: string;
 
  @Prop({ required: true })
  version: number;
 
  @Prop({ required: true })
  relativePath: string;
 
  @Prop({ required: true })
  sizeBytes: number;
 
  @Prop({ required: true })
  checksum: string;
 
  createdAt: Date;
}
export const StorageObjectVersionSchema =
  SchemaFactory.createForClass(StorageObjectVersion);
StorageObjectVersionSchema.index({ objectId: 1, version: 1 }, { unique: true });
 
@Schema({ timestamps: true, collection: 'storage_access_tokens' })
export class StorageAccessToken extends Document {
  @Prop({ required: true, unique: true, index: true })
  token: string;
 
  @Prop({ required: true, index: true })
  key: string; // Matches StorageObject key
 
  @Prop({ required: true })
  expiresAt: Date;
 
  @Prop({ default: false })
  isRevoked: boolean;
 
  createdAt: Date;
}
export const StorageAccessTokenSchema =
  SchemaFactory.createForClass(StorageAccessToken);
StorageAccessTokenSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });