node-go/packages/server/data/queries/user.js
2020-02-05 16:54:09 -08:00

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
}