All files / learning/schemas course.schema.ts

100% Statements 35/35
80% Branches 16/20
100% Functions 0/0
100% Lines 31/31

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 841x 1x     1x   1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x 1x     1x   1x     1x     1x     1x     1x 1x  
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ timestamps: true, collection: 'learning_courses' })
export class Course extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true, index: true })
  courseCode: string;
 
  @Prop({ required: true })
  title: string;
 
  @Prop()
  description: string;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'LearningCategory' })
  categoryId: MongooseSchema.Types.ObjectId;
 
  @Prop({ default: 'beginner', enum: ['beginner', 'intermediate', 'advanced'] })
  level: string;
 
  @Prop({ default: 'en' })
  language: string;
 
  @Prop({ default: 60 })
  durationMinutes: number;
 
  @Prop({ default: 'self_paced', enum: ['self_paced', 'instructor_led', 'virtual', 'blended'] })
  courseType: string;
 
  @Prop({ default: 80 })
  passingPercentage: number;
 
  @Prop({ default: 3 })
  attemptLimit: number;
 
  @Prop({ default: 365 })
  validityDays: number;
 
  @Prop({ default: true })
  certificateEnabled: boolean;
 
  @Prop({ default: 0 })
  costMinor: number;
 
  @Prop({ default: 'INR' })
  currency: string;
 
  @Prop({ default: 'draft', enum: ['draft', 'review_pending', 'approved', 'published', 'retired'] })
  status: string;
 
  @Prop({ default: 1 })
  activeVersion: number;
 
  @Prop({ type: [MongooseSchema.Types.ObjectId], ref: 'PerformanceCompetencyLibrary' })
  mappedCompetencies: MongooseSchema.Types.ObjectId[];
 
  @Prop({ type: [String] })
  skillsAcquired: string[];
}
 
export const CourseSchema = SchemaFactory.createForClass(Course);
CourseSchema.index({ tenantId: 1, courseCode: 1 }, { unique: true });
 
@Schema({ timestamps: true, collection: 'learning_course_versions' })
export class CourseVersion extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Course', required: true, index: true })
  courseId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  versionNumber: number;
 
  @Prop({ type: MongooseSchema.Types.Mixed, required: true })
  frozenCourseSnapshot: any;
}
 
export const CourseVersionSchema = SchemaFactory.createForClass(CourseVersion);
CourseVersionSchema.index({ tenantId: 1, courseId: 1, versionNumber: 1 }, { unique: true });