All files / src/platform/activity/schemas activity.schema.ts

0% Statements 0/20
0% Branches 0/4
0% Functions 0/1
0% Lines 0/18

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                                                                                                   
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ timestamps: true, collection: 'activities' })
export class Activity extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true, index: true })
  entityType: string; // e.g. "Lead", "Project", "Invoice"
 
  @Prop({ required: true, index: true })
  entityId: string;
 
  @Prop({ required: true, index: true })
  actorId: string; // User ID who performed this
 
  @Prop({ required: true })
  activityType: string; // e.g. "NOTE", "CALL", "EMAIL", "SYSTEM_UPDATE"
 
  @Prop({ required: true })
  title: string;
 
  @Prop({ default: null })
  description: string;
 
  @Prop({ default: 'Activity' })
  icon: string;
 
  @Prop({ default: 'INTERNAL' })
  visibility: string; // "INTERNAL" | "PUBLIC" (customer portal visibility)
 
  @Prop({ type: MongooseSchema.Types.Mixed, default: null })
  relatedEntity: any; // { id, type, name }
 
  @Prop({ type: MongooseSchema.Types.Mixed, default: null })
  metadata: any;
 
  @Prop({ required: true, default: () => new Date(), index: true })
  occurredAt: Date;
}
 
export const ActivitySchema = SchemaFactory.createForClass(Activity);
ActivitySchema.index({
  tenantId: 1,
  entityType: 1,
  entityId: 1,
  occurredAt: -1,
});