f052_admin_area #27

Merged
jared merged 13 commits from f052_admin_area into development 2025-08-21 11:08:45 +02:00
2 changed files with 11 additions and 10 deletions
Showing only changes of commit 9d54a0fdb8 - Show all commits

View File

@@ -15,21 +15,18 @@ export const getUsers = (): { userId: string; userName: string }[] => {
return userList;
};
export const addUser = (userName: string, userPassword: string): number => {
export const addUser = (userName: string, userPassword: string) => {
const addUserSQLStmt = `INSERT into users(name, pw)
values (?, ?)`;
const statement = db.prepare(addUserSQLStmt);
let rowCount;
let rowInfo;
try {
const info = statement.run(userName, userPassword);
rowCount = info.changes;
rowInfo = statement.run(userName, userPassword);
return rowInfo;
} catch (error) {
console.log(error);
rowCount = 0;
console.error('ERROR: ', error);
}
return rowCount;
};
export const deleteUser = (userId: string) => {

View File

@@ -24,7 +24,11 @@ export async function POST({ request, locals }) {
return json({ error: 'Missing input' }, { status: 400 });
}
const rowCount = addUser(userName, userPassword);
const rowInfo = addUser(userName, userPassword);
return new Response(null, { status: rowCount == 1 ? 200 : 400 });
if (rowInfo?.changes == 1) {
trachi93 marked this conversation as resolved Outdated
Outdated
Review

status code für created ist 201

status code für created ist 201
return json({ userId: rowInfo.lastInsertRowid, userName: userName }, { status: 201 });
} else {
return new Response(null, { status: 400 });
}
}