-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-deposit-logic.js
More file actions
141 lines (123 loc) Β· 4 KB
/
Copy pathdebug-deposit-logic.js
File metadata and controls
141 lines (123 loc) Β· 4 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const mongoose = require('mongoose');
require('dotenv').config();
// Connect to MongoDB
mongoose.connect(process.env.MONGODB_URI || 'mongodb+srv://mesum357:pDliM118811@cluster0.h3knh.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0');
// Define schemas
const userSchema = new mongoose.Schema({
username: String,
password: String,
googleId: String,
email: String,
profileImage: String,
balance: {
type: Number,
default: 0
},
hasDeposited: {
type: Boolean,
default: false
},
referralCode: {
type: String,
unique: true,
sparse: true
},
referredBy: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
createdAt: {
type: Date,
default: Date.now
},
verified: {
type: Boolean,
default: false
},
verificationToken: String,
resetPasswordToken: String,
resetPasswordExpires: Date
});
const depositSchema = new mongoose.Schema({
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
amount: {
type: Number,
required: true
},
status: {
type: String,
enum: ['pending', 'confirmed', 'rejected'],
default: 'pending'
},
receiptUrl: String,
transactionHash: String,
notes: String,
createdAt: {
type: Date,
default: Date.now
},
confirmedAt: Date
});
const User = mongoose.model('User', userSchema);
const Deposit = mongoose.model('Deposit', depositSchema);
async function debugDepositLogic() {
console.log('π Debugging deposit logic...\n');
try {
// Find the most recent test user
const user = await User.findOne({ email: { $regex: /testuser/ } }).sort({ createdAt: -1 });
if (!user) {
console.log('β No test user found');
return;
}
console.log('π€ Found test user:', user.email);
console.log('Current state:', {
balance: user.balance,
hasDeposited: user.hasDeposited,
_id: user._id
});
// Find all deposits for this user
const allDeposits = await Deposit.find({
userId: user._id
});
console.log('π° All deposits for user:', allDeposits.length);
allDeposits.forEach(dep => {
console.log(` - $${dep.amount} (${dep.status}) - ID: ${dep._id}`);
});
// Test the exact logic from the app.js file
console.log('\nπ Testing deposit logic from app.js...');
// Simulate the deposit confirmation logic
const deposit = allDeposits[0]; // Get the first deposit
if (deposit) {
console.log('π Testing with deposit:', {
amount: deposit.amount,
status: deposit.status,
userId: deposit.userId
});
// Test the countDocuments logic
const totalConfirmedDeposits = await Deposit.countDocuments({
userId: deposit.userId,
status: 'confirmed'
});
console.log('π Total confirmed deposits count:', totalConfirmedDeposits);
// Test the condition
const isFirstDeposit = totalConfirmedDeposits === 1 && deposit.amount === 10;
console.log('π Is first deposit?', isFirstDeposit);
console.log(' - totalConfirmedDeposits === 1:', totalConfirmedDeposits === 1);
console.log(' - deposit.amount === 10:', deposit.amount === 10);
if (isFirstDeposit) {
console.log('β
Should only unlock tasks, not add to balance');
} else {
console.log('β Should add to balance normally');
}
}
} catch (error) {
console.error('β Error:', error);
} finally {
await mongoose.disconnect();
}
}
debugDepositLogic();