File size: 1,244 Bytes
1d3aceb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
705e923
 
1d3aceb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import mongoose from 'mongoose';

const activityLogSchema = new mongoose.Schema({
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User',
        required: true
    },
    userEmail: String,
    action: {
        type: String,
        required: true,
        enum: [
            'ANALYZE_TENDER',
            'SUBMIT_STRATEGY',
            'GENERATE_DOCUMENT',
            'REFINE_DOCUMENT',
            'PAYMENT_INITIATED',
            'PAYMENT_SUCCESS',
            'PAYMENT_FAILED',
            'USER_REGISTERED',
            'USER_LOGIN',
            'WELCOME_CREDITS_GRANTED',
            'UPLOAD_FILES',
            'CREATE_TENDER',
            'REMOVE_FILE',
        ]
    },
    details: {
        type: mongoose.Schema.Types.Mixed,
        default: {}
    },
    creditsUsed: {
        type: Number,
        default: 0
    },
    tenderId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Tender'
    },
    tenderTitle: String,
    createdAt: {
        type: Date,
        default: Date.now
    }
});

activityLogSchema.index({ createdAt: -1 });
activityLogSchema.index({ user: 1, createdAt: -1 });

const ActivityLog = mongoose.model('ActivityLog', activityLogSchema);
export default ActivityLog;