// Méthode deleteUser à mettre à jour
async deleteUser(userId: string) {
try {
// Supprimer les positions de trading de l'utilisateur
await this.prisma.swingPosition.updateMany({
where: { userId },
data: { userId: null }
})
// Supprimer les exchanges de l'utilisateur
await this.prisma.exchange.updateMany({
where: { userId },
data: { userId: null }
})
// Supprimer l'utilisateur (cascade supprimera les sessions, accounts, etc.)
await this.prisma.user.delete({
where: { id: userId }
})
return true
} catch (error) {
console.error("Error deleting user:", error)
throw error
}
}
// Méthode getUserStats à mettre à jour
async getUserStats(userId: string) {
try {
const [swingPositions, exchanges, totalPnl] = await Promise.all([
this.prisma.swingPosition.count({
where: { userId }
}),
this.prisma.exchange.count({
where: { userId }
}),
this.prisma.swingPosition.aggregate({
where: { userId },
_sum: { pnl: true }
})
])
return {
swingPositions,
exchanges,
totalPnl: totalPnl._sum.pnl || 0
}
} catch (error) {
console.error("Error getting user stats:", error)
throw error
}
}