All files / src/platform/documents/schemas storage.schema.ts

0% Statements 0/59
0% Branches 0/8
100% Functions 0/0
0% Lines 0/47

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                                                                                                                                                                                                                                                       
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ timestamps: true, collection: 'folders' })
export class Folder extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true })
  name: string;
 
  @Prop({ default: null })
  parentFolderId: string;
 
  @Prop({ required: true })
  path: string; // e.g. "/documents/finance"
 
  @Prop({ required: true })
  ownerId: string;
}
export const FolderSchema = SchemaFactory.createForClass(Folder);
 
@Schema({ timestamps: true, collection: 'files' })
export class FileDocument extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ default: null, index: true })
  folderId: string;
 
  @Prop({ required: true })
  name: string;
 
  @Prop({ required: true })
  mimeType: string;
 
  @Prop({ required: true })
  size: number; // Bytes
 
  @Prop({ required: true })
  s3Key: string;
 
  @Prop({ default: false })
  isPublic: boolean;
 
  @Prop({ required: true })
  ownerId: string;
 
  @Prop({ type: [String], default: [] })
  tags: string[];
 
  @Prop({ default: null })
  deletedAt: Date;
}
export const FileDocumentSchema = SchemaFactory.createForClass(FileDocument);
FileDocumentSchema.index({ tenantId: 1, folderId: 1 });
 
@Schema({ timestamps: true, collection: 'file_versions' })
export class FileVersion extends Document {
  @Prop({ required: true, index: true })
  documentId: string;
 
  @Prop({ required: true })
  version: number;
 
  @Prop({ required: true })
  s3Key: string;
 
  @Prop({ required: true })
  size: number;
 
  @Prop({ required: true })
  createdById: string;
}
export const FileVersionSchema = SchemaFactory.createForClass(FileVersion);
 
@Schema({ timestamps: true, collection: 'file_shares' })
export class FileShare extends Document {
  @Prop({ required: true, index: true })
  documentId: string;
 
  @Prop({ required: true, unique: true })
  token: string;
 
  @Prop({ default: null })
  expiresAt: Date;
 
  @Prop({ default: null })
  passwordHash: string;
}
export const FileShareSchema = SchemaFactory.createForClass(FileShare);
 
@Schema({ timestamps: true, collection: 'upload_sessions' })
export class UploadSession extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true, unique: true })
  uploadId: string;
 
  @Prop({ required: true })
  status: string; // 'INITIATED' | 'COMPLETED' | 'CANCELLED'
 
  @Prop({ required: true })
  size: number;
 
  @Prop({ required: true })
  expectedChunks: number;
}
export const UploadSessionSchema = SchemaFactory.createForClass(UploadSession);
 
@Schema({ timestamps: true, collection: 'storage_usages' })
export class StorageUsage extends Document {
  @Prop({ required: true, unique: true, index: true })
  tenantId: string;
 
  @Prop({ required: true, default: 0 })
  currentBytes: number;
 
  @Prop({ required: true, default: 53687091200 }) // Default 50GB in bytes
  maxBytes: number;
}
export const StorageUsageSchema = SchemaFactory.createForClass(StorageUsage);