All files / knowledge/schemas wiki.schema.ts

100% Statements 24/24
80% Branches 20/25
100% Functions 0/0
100% Lines 20/20

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 511x 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: 'wiki_spaces' })
export class WikiSpace extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  name: string;
 
  @Prop({ required: true, unique: true, index: true })
  key: string; // e.g. "ENG", "HR"
 
  @Prop({ default: '' })
  description?: string;
}
 
export const WikiSpaceSchema = SchemaFactory.createForClass(WikiSpace);
 
@Schema({ timestamps: true, collection: 'wiki_pages' })
export class WikiPage extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'WikiSpace', required: true, index: true })
  spaceId: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'WikiPage', default: null, index: true })
  parentId?: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  title: string;
 
  @Prop({ required: true })
  slug: string;
 
  @Prop({ required: true })
  content: string;
 
  @Prop({ default: 1 })
  version: number;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Employee' })
  lastModifiedBy?: MongooseSchema.Types.ObjectId;
}
 
export const WikiPageSchema = SchemaFactory.createForClass(WikiPage);
WikiPageSchema.index({ tenantId: 1, spaceId: 1, slug: 1 }, { unique: true });
WikiPageSchema.index({ tenantId: 1, parentId: 1 });