File size: 1,232 Bytes
644d830
 
 
 
 
 
e1a5ce8
644d830
 
ca4fcfa
a569cab
644d830
 
e1a5ce8
644d830
 
 
 
e1a5ce8
 
 
 
 
644d830
 
 
e1a5ce8
644d830
 
e1a5ce8
a569cab
e1a5ce8
644d830
 
 
 
 
 
 
 
 
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
import * as mongoose from 'mongoose';
import { Document } from 'mongoose';
import { IUserDocument } from '../user/user.schema';
import { IPropertyDocument } from '../property/property.schema';

export interface IUserActivityDocument extends Document {
  // userId: IUserDocument;
  propertyId: IPropertyDocument;
  action: string; // E.g., 'click', 'view', 'time_spent'
  sessionId: string;
  id: string;
  timestamp: Date;
  duration?: number; // Store time spent in seconds for 'time_spent' action
  searchQuery?: string;
}

const UserActivitySchema = new mongoose.Schema<IUserActivityDocument>(
  {
    // userId: {
    //   type: mongoose.Schema.Types.ObjectId,
    //   ref: 'User',
    //   required: true,
    // },
    propertyId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'propertie',
      // required: true,
    },
    action: { type: String, required: true }, // 'click', 'view', 'time_spent'
    sessionId: { type: String, required: true },
    id: { type: String },
    searchQuery: { type: String },
    timestamp: { type: Date, default: Date.now },
    duration: { type: Number }, // Only applicable for 'time_spent'
  },
  {
    toJSON: { versionKey: false },
  },
);

export { UserActivitySchema };