Skip to content

Instantly share code, notes, and snippets.

@rohitsaini1196
Created June 2, 2021 00:50
Show Gist options
  • Save rohitsaini1196/13658e48585c58378a56c51643c73060 to your computer and use it in GitHub Desktop.
Save rohitsaini1196/13658e48585c58378a56c51643c73060 to your computer and use it in GitHub Desktop.
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