Skip to content

Instantly share code, notes, and snippets.

@vladotesanovic
Created April 7, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladotesanovic/f7eb6a2ad07227cdcc6867623f091917 to your computer and use it in GitHub Desktop.
Save vladotesanovic/f7eb6a2ad07227cdcc6867623f091917 to your computer and use it in GitHub Desktop.
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
const express_1 = require("express");
const model_1 = require("../models/post/model");
const model_2 = require("../models/author/model");
class PostRouter {
static routes() {
return express_1.Router()
.get("/post", (request, response) => __awaiter(this, void 0, void 0, function* () {
const posts = yield model_1.Post.find({}).populate("author").exec();
response.json(posts);
}))
.post("/post", (request, response) => __awaiter(this, void 0, void 0, function* () {
let data = request.body;
let author = yield model_2.Author.findOne().exec();
data.author = author._id;
const post = yield model_1.Post.create(data);
response.json(post);
}));
}
}
exports.PostRouter = PostRouter;
//# sourceMappingURL=post.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment