Skip to content

Commit

Permalink
✨ Adds user model.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisjcarr committed Sep 8, 2019
1 parent 77609c4 commit 9189794
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions data/models/usersModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const db = require("../dbConfig");

module.exports = {
add,
find,
findBy,
findById
};

async function find() {
return await db("users").select("id", "username", "password");
}

async function findBy(filter) {
return await db("users")
.where(filter)
.first();
}

async function add(user) {
const ids = await db("users").insert(user, "id");
const [id] = ids;
return findById(id);
}

async function findById(id) {
return await db("users")
.where({ id })
.first();
}

0 comments on commit 9189794

Please sign in to comment.