handle-result.js
453 Bytes
const _ = require('lodash');
module.exports = (result, apiInfo) => {
if (result.code === 200 && _.isObject(apiInfo.fields)) {
console.log(apiInfo.fields);
let resData = result.data || {};
let data = {};
_.forEach(apiInfo.fields, (v, k) => {
if (!_.has(resData, k) && _.has(v, 'default')) {
data[k] = v.default;
} else {
data[k] = resData[k]
}
});
result.data = data;
}
return result;
};