All files / models User.js

44.44% Statements 4/9
100% Branches 0/0
16.66% Functions 1/6
44.44% Lines 4/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39  2x   2x   6x                                                               2x  
// User model
const { getOne, getAll, run } = require("./query");
 
const User = {
  async findByUsername(username) {
    return getOne("SELECT * FROM users WHERE username = ?", [username]);
  },
 
  async findById(userId) {
    return getOne("SELECT * FROM users WHERE user_id = ?", [userId]);
  },
 
  async getAll() {
    return getAll(
      "SELECT user_id, username, full_name, role, created_at FROM users",
    );
  },
 
  async create(username, password, fullName, role) {
    return run(
      "INSERT INTO users (username, password, full_name, role) VALUES (?, ?, ?, ?)",
      [username, password, fullName, role],
    );
  },
 
  async update(userId, username, fullName, role) {
    return run(
      "UPDATE users SET username = ?, full_name = ?, role = ? WHERE user_id = ?",
      [username, fullName, role, userId],
    );
  },
 
  async delete(userId) {
    return run("DELETE FROM users WHERE user_id = ?", [userId]);
  },
};
 
module.exports = User;