Fix accounts model

This commit is contained in:
rui hildt 2020-05-01 18:24:59 +02:00
parent 7e4d186446
commit dc3e0d0b18
2 changed files with 11 additions and 16 deletions

View File

@ -1,18 +1,14 @@
const db = require('../../data/dbConfig');
module.exports = {
addUser
addUser,
};
function addUser(userData) {
db.one('INSERT INTO account VALUES("", ${username}, ${email}, ${password}, ${timezone}, ${earliest_time}, ${latest_time}) RETURNING *', userData)
.then(data => {
console.log(data);
return data;
})
.catch(error => {
console.log('ERROR:', error);
});
};
// TODO Complete query without providing id
// right now if ID is not provided, pg-promise send an erro fo mising column
return db.one(
'INSERT INTO account VALUES(emptyUpdate, ${username}, ${email}, ${password}, ${timezone}, ${earliest_time}, ${latest_time}) RETURNING *',
userData,
);
}

View File

@ -3,7 +3,6 @@ let router = express.Router();
let Account = require('../models/accountModel');
// Add a user
router.post('/', async (req, res) => {
const userData = { ...req.body };
@ -11,8 +10,8 @@ router.post('/', async (req, res) => {
try {
const user = await Account.addUser(userData);
res.status(201).json(user);
} catch {
res.status(500).json({ message: "Failed to add new user" });
} catch (error) {
res.status(500).json({ message: 'Failed to add new user', error });
}
});