Add authentication endpoints with logic
This commit is contained in:
25
services/users/usersModel.js
Normal file
25
services/users/usersModel.js
Normal 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');
|
||||
}
|
||||
Reference in New Issue
Block a user