All files / src/domains/projects/schemas project.schema.ts

0% Statements 0/51
0% Branches 0/69
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                                                                                                                                                                                 
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ collection: 'projects', timestamps: true })
export class Project extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true }) projectCode!: string;
  @Prop({ required: true }) projectName!: string;
  @Prop() description?: string;
  @Prop({ type: MongooseSchema.Types.ObjectId })
  clientId?: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId })
  projectManagerId?: MongooseSchema.Types.ObjectId;
 
  @Prop({
    required: true,
    enum: ['draft', 'active', 'on_hold', 'completed', 'cancelled', 'archived'],
  })
  status!: string;
  @Prop({ required: true, enum: ['low', 'medium', 'high', 'critical'] })
  priority!: string;
  @Prop({
    required: true,
    enum: ['on_track', 'at_risk', 'off_track', 'unknown'],
  })
  health!: string;
 
  @Prop({ required: true }) startDate!: Date;
  @Prop() targetEndDate?: Date;
  @Prop() actualEndDate?: Date;
 
  @Prop({
    required: true,
    enum: ['time_and_materials', 'fixed_price', 'non_billable', 'retainer'],
  })
  billingMethod!: string;
  @Prop({ default: 'INR' }) currency!: string;
  @Prop({ default: 0 }) totalBudget?: number;
 
  @Prop({ type: MongooseSchema.Types.Mixed, default: {} })
  progressMetrics!: Record<string, unknown>;
  @Prop({ type: [String], default: [] }) tags!: string[];
 
  @Prop({ type: MongooseSchema.Types.ObjectId })
  createdBy?: MongooseSchema.Types.ObjectId;
}
export const ProjectSchema = SchemaFactory.createForClass(Project);
ProjectSchema.index({ tenantId: 1, projectCode: 1 }, { unique: true });
 
@Schema({ collection: 'project_members', timestamps: true })
export class ProjectMember extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  projectId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  employeeId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true, enum: ['manager', 'member', 'viewer', 'client'] })
  role!: string;
  @Prop({ default: 0 }) billingRate?: number;
  @Prop({ default: 0 }) costRate?: number;
  @Prop({ default: true }) isActive!: boolean;
  @Prop() allocationPercentage?: number;
}
export const ProjectMemberSchema = SchemaFactory.createForClass(ProjectMember);
ProjectMemberSchema.index(
  { tenantId: 1, projectId: 1, employeeId: 1 },
  { unique: true },
);
 
@Schema({ collection: 'project_milestones', timestamps: true })
export class ProjectMilestone extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  projectId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true }) milestoneName!: string;
  @Prop() description?: string;
  @Prop({ required: true }) targetDate!: Date;
  @Prop() completionDate?: Date;
  @Prop({ required: true, enum: ['pending', 'in_progress', 'completed'] })
  status!: string;
  @Prop() amount?: number;
  @Prop({ default: false }) invoiced!: boolean;
}
export const ProjectMilestoneSchema =
  SchemaFactory.createForClass(ProjectMilestone);