Modifs pour rewards + ajout J/leaderboard

This commit is contained in:
Zachary Guénot
2023-05-23 22:47:56 +02:00
parent 327e2d8a05
commit 1d9432c0aa
3 changed files with 75 additions and 20 deletions

View File

@@ -17,8 +17,6 @@ module.exports = modifyReward = (async (viewer_id, viewer_name, action, quantity
// Check if the viewer already exists in the rewards table
await connection.query('SELECT * FROM rewards WHERE viewer_id = ?', [viewer_id])
.then(async ([rows, fields]) => {
console.log(rows)
if (rows.length === 0) {
// Viewer doesn't exist, insert a new row
sql_data = { viewer_id, viewer_name }
@@ -44,6 +42,8 @@ module.exports = modifyReward = (async (viewer_id, viewer_name, action, quantity
if (type === 'permanent') sql_data.count = rows[0].count + quantity
else if (type === 'current') sql_data.current_count = rows[0].current_count + quantity
else { sql_data.count = rows[0].count + quantity; sql_data.current_count = rows[0].current_count + quantity }
result.status = 'update_add_entry'
}
else if (action === 'remove') { // Remove the quantity
if (type === 'permanent') sql_data.count = rows[0].count - quantity
@@ -52,15 +52,18 @@ module.exports = modifyReward = (async (viewer_id, viewer_name, action, quantity
if (sql_data.count < 0) return result.status = 'not_enough_count' // Can't delete more than the count
if (sql_data.current_count < 0) return result.status = 'not_enough_current_count' // Can't delete more than the current_count
result.status = 'update_remove_entry'
}
else if (action === 'set') { // Set the quantity
if (type === 'permanent') sql_data.count = quantity
else if (type === 'current') sql_data.current_count = quantity
else { sql_data.count = quantity; sql_data.current_count = quantity }
result.status = 'update_set_entry'
}
await connection.query('UPDATE rewards SET ? WHERE viewer_id = ?', [sql_data, viewer_id]).catch(error => { console.error(error) })
return result.status = 'update_entry'
}
}).catch(error => { console.error(error) })