node-go/server/data/queries/user.js

27 lines
626 B
JavaScript
Raw Permalink Normal View History

const knex = require('../db')
2020-01-18 00:32:40 +00:00
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) => {
2020-01-18 00:32:40 +00:00
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
}