refactor addUser API endpoint to return user object if successful
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user