| Server IP : 167.235.67.158 / Your IP : 216.73.216.95 Web Server : Apache System : Linux ubuntu-8gb-nbg1-1 6.8.0-111-generic #111-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 11 23:16:02 UTC 2026 x86_64 User : upstairsbar.co.uk ( 982) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/api.pda.the-word.com/user/ |
Upload File : |
const helpers = require('../common/helpers');
const { queryDatabase, updateRows } = require('../common/sqlDB');
function mapUser(row) {
return {
id: Number(row.ID),
name: row.Name || '',
credits: Number(row.Credits || 0),
settings: row.Settings || '',
role: Number(row.Role || 0),
reminderTimer: Number(row.ReminderTimer || 1),
workingHours: row.WorkingHours || ''
};
}
async function getCurrentUser(userId) {
const rows = await queryDatabase(
`SELECT ID, Name, Credits, Settings, Role, ReminderTimer, WorkingHours
FROM Users
WHERE ID = ? AND Deleted = 0
LIMIT 1`,
[userId]
);
if (!rows.length) {
const error = new Error('User not found.');
error.statusCode = 404;
throw error;
}
return mapUser(rows[0]);
}
async function updateCurrentUser(userId, body) {
helpers.requireFields(body, ['settings', 'reminderTimer', 'workingHours']);
await updateRows('Users', {
Settings: body.settings,
ReminderTimer: Number(body.reminderTimer),
WorkingHours: body.workingHours
}, 'ID = ? AND Deleted = 0', [userId]);
return getCurrentUser(userId);
}
module.exports = {
getCurrentUser,
updateCurrentUser
};