feat: add scripts for player deduplication and user management
This commit is contained in:
Executable
+74
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Script to update a user's name (for superuser/admin use)
|
||||
* Usage: node scripts/update-user-name.js <userId> <newName>
|
||||
*/
|
||||
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function updateUserName(userId, newName) {
|
||||
if (!userId || !newName) {
|
||||
console.error('Usage: node scripts/update-user-name.js <userId> <newName>');
|
||||
console.error('Example: node scripts/update-user-name.js "user-123" "John Doe"');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if user exists
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
include: { player: true },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
console.error(`❌ User with ID "${userId}" not found`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Found user: ${user.name} (${user.email})`);
|
||||
|
||||
// Update user name
|
||||
const updatedUser = await prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
name: newName,
|
||||
...(user.player && {
|
||||
player: {
|
||||
update: {
|
||||
name: newName,
|
||||
normalizedName: newName.toLowerCase(),
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
include: { player: true },
|
||||
});
|
||||
|
||||
console.log(`✅ Successfully updated user name to "${newName}"`);
|
||||
console.log(` User ID: ${updatedUser.id}`);
|
||||
console.log(` Email: ${updatedUser.email}`);
|
||||
console.log(` New Name: ${updatedUser.name}`);
|
||||
|
||||
if (updatedUser.player) {
|
||||
console.log(` Player Name: ${updatedUser.player.name}`);
|
||||
}
|
||||
|
||||
return updatedUser;
|
||||
} catch (error) {
|
||||
console.error('❌ Error updating user name:', error.message);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
// Run if called directly
|
||||
if (require.main === module) {
|
||||
const userId = process.argv[2];
|
||||
const newName = process.argv[3];
|
||||
updateUserName(userId, newName);
|
||||
}
|
||||
|
||||
module.exports = { updateUserName };
|
||||
Reference in New Issue
Block a user