27 lines
No EOL
626 B
JavaScript
27 lines
No EOL
626 B
JavaScript
const knex = require('../db')
|
|
|
|
const insertUser = async (user) => {
|
|
return await knex('user')
|
|
.returning(['username', 'email', 'id'])
|
|
.insert(user)
|
|
.then(queryResults => {
|
|
newUser = queryResults[0];
|
|
return newUser
|
|
});
|
|
}
|
|
|
|
const findUserByNameOrEmail = async (user) => {
|
|
if (!user.email && !user.username) return [];
|
|
if (!user.email) user.email = '';
|
|
if (!user.username) user.username = '';
|
|
|
|
return await knex('user')
|
|
.where({'username': user.username})
|
|
.orWhere({'email': user.email})
|
|
.select(['username', 'email', 'password', 'id'])
|
|
}
|
|
|
|
module.exports = {
|
|
insertUser,
|
|
findUserByNameOrEmail
|
|
} |