All files / app/middleware body.middleware.js

100% Statements 11/11
100% Branches 2/2
100% Functions 4/4
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211x   1x   61x 53x 53x 53x 52x   1x 1x   53x       53x      
const body = require('koa-body');
 
module.exports = function (options) {
 
    return async function (ctx, next) {
        await body(options)(ctx, function () {
            return new Promise((resolve, reject) => {
                if (!ctx.request.body.files) {
                    ctx.post = ctx.request.body;
                } else {
                    ctx.post = ctx.request.body.fields;
                    ctx.file = ctx.request.body.files;
                }
                resolve(true);
            });
        });
 
        await next();
    }
};