sleep-tracker-backend/services/users/usersModel.js

26 lines
373 B
JavaScript
Raw Normal View History

const db = require('../../data/dbConfig');
module.exports = {
add,
findBy,
findById,
};
function findBy(filter) {
return db('users')
.where(filter);
}
async function add(user) {
const [id] = await db('users')
.insert(user);
return findById(id);
}
function findById(id) {
return db('users')
.where({ id })
.first()
.select('id', 'email', 'username');
}