+ hudozka-middlewares, + hudozka-api-v1

This commit is contained in:
tmshv committed 2016-03-26 21:53:20 +03:00
1 parent 6347e4db35
commit 35cc7c0caa
17 files changed
+175 -61

No files matched your search

@@ -0,0 +1,30 @@
import {put} from 'koa-route';
import compose from 'koa-compose';
import hm from 'hudozka-middlewares';
import query from 'koa-query';
import {toBoolean} from 'koa-query';
export function add(auth, data) {
return put('/timeline', compose([
hm.ensureServiceAuth(auth),
hm.ejson(),
query({
save: toBoolean()
}),
async(ctx) => {
let doSave = ctx.request.query.save || true;
let post = ctx.request.body;
try {
if(!doSave) data.timeline.disableSaving();
let result = await data.timeline.add(post);
if(!doSave) data.timeline.enableSaving();
ctx.body = result;
} catch (e) {
ctx.status = 400;
ctx.body = e;
}
}
]));
}