feat: Add initial identifier field to user management and update related functions

This commit is contained in:
2025-09-29 19:41:49 +02:00
parent fc5f0fd39a
commit e589d6667f
3 changed files with 34 additions and 6 deletions

View File

@@ -19,7 +19,7 @@ export async function createUser({ name, username, password, role = 'user', is_a
return db.prepare(`
SELECT id, name, username, role, created_at, updated_at, last_login,
is_active, failed_login_attempts, locked_until
is_active, failed_login_attempts, locked_until, initial
FROM users WHERE id = ?
`).get(userId)
}
@@ -28,7 +28,7 @@ export async function createUser({ name, username, password, role = 'user', is_a
export function getUserById(id) {
return db.prepare(`
SELECT id, name, username, password_hash, role, created_at, updated_at, last_login,
is_active, failed_login_attempts, locked_until
is_active, failed_login_attempts, locked_until, initial
FROM users WHERE id = ?
`).get(id)
}
@@ -36,7 +36,7 @@ export function getUserById(id) {
// Get user by username
export function getUserByUsername(username) {
return db.prepare(`
SELECT id, name, username, role, created_at, last_login, is_active
SELECT id, name, username, role, created_at, last_login, is_active, initial
FROM users WHERE username = ?
`).get(username)
}
@@ -45,7 +45,7 @@ export function getUserByUsername(username) {
export function getAllUsers() {
return db.prepare(`
SELECT id, name, username, password_hash, role, created_at, updated_at, last_login, is_active,
failed_login_attempts, locked_until
failed_login_attempts, locked_until, initial
FROM users
ORDER BY created_at DESC
`).all()
@@ -172,6 +172,11 @@ export async function updateUser(userId, updates) {
updateValues.push(updates.is_active ? 1 : 0);
}
if (updates.initial !== undefined) {
updateFields.push("initial = ?");
updateValues.push(updates.initial);
}
if (updates.password !== undefined) {
const passwordHash = await bcrypt.hash(updates.password, 12);
updateFields.push("password_hash = ?");
@@ -199,7 +204,7 @@ export async function updateUser(userId, updates) {
if (result.changes > 0) {
return db.prepare(`
SELECT id, name, username, role, created_at, updated_at, last_login,
is_active, failed_login_attempts, locked_until
is_active, failed_login_attempts, locked_until, initial
FROM users WHERE id = ?
`).get(userId);
}