Fix accounts model
This commit is contained in:
parent
7e4d186446
commit
dc3e0d0b18
@ -1,18 +1,14 @@
|
|||||||
const db = require('../../data/dbConfig');
|
const db = require('../../data/dbConfig');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addUser
|
addUser,
|
||||||
};
|
};
|
||||||
|
|
||||||
function addUser(userData) {
|
function addUser(userData) {
|
||||||
db.one('INSERT INTO account VALUES("", ${username}, ${email}, ${password}, ${timezone}, ${earliest_time}, ${latest_time}) RETURNING *', userData)
|
// TODO Complete query without providing id
|
||||||
.then(data => {
|
// right now if ID is not provided, pg-promise send an erro fo mising column
|
||||||
console.log(data);
|
return db.one(
|
||||||
return data;
|
'INSERT INTO account VALUES(emptyUpdate, ${username}, ${email}, ${password}, ${timezone}, ${earliest_time}, ${latest_time}) RETURNING *',
|
||||||
})
|
userData,
|
||||||
.catch(error => {
|
);
|
||||||
console.log('ERROR:', error);
|
}
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
@ -3,16 +3,15 @@ let router = express.Router();
|
|||||||
|
|
||||||
let Account = require('../models/accountModel');
|
let Account = require('../models/accountModel');
|
||||||
|
|
||||||
|
|
||||||
// Add a user
|
// Add a user
|
||||||
router.post('/', async (req, res) => {
|
router.post('/', async (req, res) => {
|
||||||
const userData = {...req.body};
|
const userData = { ...req.body };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const user = await Account.addUser(userData);
|
const user = await Account.addUser(userData);
|
||||||
res.status(201).json(user);
|
res.status(201).json(user);
|
||||||
} catch {
|
} catch (error) {
|
||||||
res.status(500).json({ message: "Failed to add new user" });
|
res.status(500).json({ message: 'Failed to add new user', error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user