Add authentication endpoints with logic

This commit is contained in:
2019-08-01 08:55:37 +02:00
parent 6c562ee7f6
commit d97221e522
5 changed files with 114 additions and 2 deletions

View File

@@ -0,0 +1,25 @@
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');
}