Files
TurboTrades/make-admin.js
2026-01-10 04:57:43 +00:00

60 lines
1.8 KiB
JavaScript

import mongoose from 'mongoose';
import dotenv from 'dotenv';
// Load environment variables
dotenv.config();
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/turbotrades';
const STEAM_ID = '76561198027608071'; // Your Steam ID
async function makeAdmin() {
try {
console.log('🔌 Connecting to MongoDB...');
await mongoose.connect(MONGODB_URI);
console.log('✅ Connected to MongoDB');
const User = mongoose.model('User', new mongoose.Schema({
username: String,
steamId: String,
avatar: String,
staffLevel: Number,
}));
console.log(`🔍 Looking for user with Steam ID: ${STEAM_ID}`);
const user = await User.findOne({ steamId: STEAM_ID });
if (!user) {
console.error(`❌ User with Steam ID ${STEAM_ID} not found!`);
console.log(' Make sure you have logged in via Steam at least once.');
process.exit(1);
}
console.log(`✅ Found user: ${user.username}`);
console.log(` Current staff level: ${user.staffLevel || 0}`);
// Update staff level to 3 (admin)
user.staffLevel = 3;
await user.save();
console.log('✅ Successfully updated user to admin (staffLevel: 3)');
console.log(' You now have access to admin routes:');
console.log(' - POST /api/admin/prices/update');
console.log(' - GET /api/admin/prices/status');
console.log(' - GET /api/admin/prices/missing');
console.log(' - POST /api/admin/prices/estimate');
console.log(' - GET /api/admin/stats');
console.log(' - And more...');
await mongoose.disconnect();
console.log('\n🎉 Done! Please restart your backend server.');
process.exit(0);
} catch (error) {
console.error('❌ Error:', error.message);
process.exit(1);
}
}
makeAdmin();