Created
June 2, 2021 00:50
-
-
Save rohitsaini1196/13658e48585c58378a56c51643c73060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
postSomething: async (req, res) => { | |
const { title, description, userId } = req.body; | |
const thing = new Field({ | |
title, | |
description, | |
userId, | |
}); | |
try { | |
const newThing = await thing.save(); | |
res.json(newThing); | |
} catch (error) { | |
res.status(400).send(error); | |
} | |
}, | |
getSomething: async (req, res) => { | |
const { username } = req.params; | |
console.log(username); | |
try { | |
const thing = await Field.findOne({ username }); | |
if (!thing) { | |
return res.status(404).send("Thing Not found"); | |
} | |
res.status(200).json(thing); | |
} catch (error) { | |
res.status(400).send(error); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment