user list and possibility of adding new users implemented on FE and BE

This commit is contained in:
2025-08-06 08:37:24 +02:00
parent b5ff4a72fb
commit 26b94938a9
4 changed files with 253 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { db } from '$lib/server/dbService';
export const getUsers = (): { userId: string; userName: string }[] => {
const getUsersSQLStmt = `SELECT id, name
FROM users;`;
const statement = db.prepare(getUsersSQLStmt);
const result = statement.all() as { id: string; name: string }[];
const userList: { userId: string; userName: string }[] = [];
for (const resultItem of result) {
const user = { userId: resultItem.id, userName: resultItem.name };
userList.push(user);
}
return userList;
};
export const addUser = (userName: string, userPassword: string): number => {
const addUserSQLStmt = `INSERT into users(name, pw)
values (?, ?)`;
const statement = db.prepare(addUserSQLStmt);
let rowCount;
try {
const info = statement.run(userName, userPassword);
rowCount = info.changes;
} catch (error) {
console.log(error);
rowCount = 0;
}
return rowCount;
};
export const deleteUser = () => {
};