26 lines
373 B
JavaScript
26 lines
373 B
JavaScript
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');
|
|
}
|