|
|
|
@@ -1,3 +1,5 @@ |
|
|
|
const { Router } = require("express") |
|
|
|
|
|
|
|
const getAll = async (req, res) => { |
|
|
|
try { |
|
|
|
if (Object.entries(req.params).length === 0) { |
|
|
|
@@ -38,5 +40,47 @@ const create = async (req, res, userModel) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const updateUser = async (req, res) => { |
|
|
|
userFound = true |
|
|
|
try { |
|
|
|
if (Object.entries(req.body).length == 0) { |
|
|
|
return res.status(400).send('invalid input parameters') |
|
|
|
} |
|
|
|
if (!userFound) { |
|
|
|
return res.status(404).send('user not found') |
|
|
|
} |
|
|
|
return res.status(200).send('user updated successfully') |
|
|
|
} catch (e) { |
|
|
|
return res.status(500).send(e) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const updateUserContacts = async (req, res) => { |
|
|
|
try { |
|
|
|
userFound = true |
|
|
|
if (!userFound) { |
|
|
|
return res.status(404).send('user not found') |
|
|
|
} |
|
|
|
if (Object.entries(req.body).length == 0) { |
|
|
|
return res.status(400).send('invalid input parameters') |
|
|
|
} |
|
|
|
return res.status(200).send('user contacts updated successfully') |
|
|
|
} catch (e) { |
|
|
|
return res.status(500).send(e) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const deleteUser = async (req, res) => { |
|
|
|
try { |
|
|
|
if (req.params.id) { |
|
|
|
//get by Id |
|
|
|
return res.status(204).send('deleting user with id of ' + req.params.id) |
|
|
|
} else { |
|
|
|
return res.status(400).send('Bad request') |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
return res.status(500).send(e) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = {getAll, getById, create} |
|
|
|
module.exports = { getAll, getById, create, updateUser, updateUserContacts, deleteUser } |