node-go/server/data/queries/user.js
2020-01-17 16:32:40 -08:00

27 lines
No EOL
614 B
JavaScript

const knex = require('../db')
const insertUser = async (user) => {
return await knex('user')
.returning(['username', 'email'])
.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'])
}
module.exports = {
insertUser,
findUserByNameOrEmail
}