Switched to ok from success on API responses

This commit is contained in:
Jori Lallo
2016-09-11 15:48:03 -07:00
parent b03d6aa116
commit 60e9a700de
4 changed files with 9 additions and 10 deletions

View File

@ -1,7 +1,7 @@
exports[`test should require authentication 1`] = ` exports[`test should require authentication 1`] = `
Object { Object {
"error": "Authentication required", "error": "Authentication required",
"success": false "ok": false
} }
`; `;
@ -13,6 +13,6 @@ Object {
"name": "User 1", "name": "User 1",
"username": "user1" "username": "user1"
}, },
"success": true "ok": true
} }
`; `;

View File

@ -1,5 +1,4 @@
import bodyParser from 'koa-bodyparser'; import bodyParser from 'koa-bodyparser';
import httpErrors from 'http-errors';
import Koa from 'koa'; import Koa from 'koa';
import Router from 'koa-router'; import Router from 'koa-router';
import Sequelize from 'sequelize'; import Sequelize from 'sequelize';
@ -41,7 +40,7 @@ api.use(async (ctx, next) => {
} }
ctx.body = { ctx.body = {
success: false, ok: false,
error: message, error: message,
}; };
} }

View File

@ -2,11 +2,11 @@ export default function apiWrapper(_options) {
return async function apiWrapperMiddleware(ctx, next) { return async function apiWrapperMiddleware(ctx, next) {
await next(); await next();
const success = ctx.status < 400; const ok = ctx.status < 400;
ctx.body = { ctx.body = {
...ctx.body, ...ctx.body,
success, ok,
}; };
}; };
} }

View File

@ -1,13 +1,13 @@
import queryString from 'query-string'; import queryString from 'query-string';
export default function methodOverride(options) { export default function methodOverride(_options) {
return async function methodOverrideMiddleware(ctx, next) { return async function methodOverrideMiddleware(ctx, next) {
if (ctx.method === 'POST') { if (ctx.method === 'POST') {
ctx.body = ctx.request.body; ctx.body = ctx.request.body;
} else if (ctx.method === 'GET') { } else if (ctx.method === 'GET') {
ctx.method= 'POST'; ctx.method= 'POST'; // eslint-disable-line
ctx.body = queryString.parse(ctx.querystring); ctx.body = queryString.parse(ctx.querystring);
} }
return next(); return next();
}
}; };
}