Skip to content

Instantly share code, notes, and snippets.

@Fabianopb
Created September 16, 2018 12:15
Show Gist options
  • Save Fabianopb/63b9d04748c127f8149953f1a5a9a143 to your computer and use it in GitHub Desktop.
Save Fabianopb/63b9d04748c127f8149953f1a5a9a143 to your computer and use it in GitHub Desktop.
Items controller for express-react-ts-ci Medium post
import * as bodyParser from "body-parser";
import * as express from "express";
import { authorize } from "../config";
import Item from "./item.model";
const router = express.Router();
router.route("/").get(authorize, async (request, response) => {
const items = await Item.find();
return response.status(200).json(items);
});
router.route("/").post(authorize, bodyParser.json(), async (request, response) => {
try {
const item = new Item(request.body);
await item.save();
return response.status(200).json("Item saved!");
} catch (error) {
return response.status(400).send(error);
}
});
export default router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment