import * as Builder from 'src/server/modules/build';
import * as Queries from 'src/server/modules/queries';

export const publish = async (req, res, next) => {
  const post = await Queries.post(req.params.id);
  post.lastPublished = Date.now();
  post.publishedMarkdown = post.markdown;
  post.save()
    .then(Queries.publishedPosts)
    .then(Builder.rebuild)
    .then(() => res.send('OK'))
    .catch(err => next(err));
}

export const unpublish = async (req, res, next) => {
  const post = await Queries.post(req.params.id);
  post.lastPublished = null;
  post.publishedMarkdown = '';
  post.save()
    .then(Queries.publishedPosts)
    .then(Builder.rebuild)
    .then(() => res.send('OK'))
    .catch(err => next(err));
}

@@ -282,38 +282,89 @@
 down;%0A  
-post.save()%0A    .then(
+const newPost = await post.save()%0A    .catch(err =%3E next(err));%0A%0A  await 
 Queries.
@@ -369,32 +369,33 @@
 s.publishedPosts
+(
 )%0A    .then(Buil
@@ -416,40 +416,8 @@
    .
-then(() =%3E res.send('OK'))%0A    .
 catc
@@ -430,24 +430,46 @@
 =%3E next(err)
+);%0A%0A  res.json(newPost
 );%0A%7D%0A%0Aexport

Return new post on save