带有rest-connector的远程方法的意外响应

时间:2018-07-11 08:48:59

标签: rest loopbackjs loopback

我尝试将Loopback.js与REST连接器一起使用以创建API网关。

我从带有rest-connector的远程方法中得到了意外响应,我做了这个远程方法:

  // PATCH /act/{id}
  Act.patchActById = async(idAct, act) => {
    const update = act.__data;
    const result = await Act.updateActByRestInAnotherService(idAct, update);
    console.log('result: ', typeof result, result); // -> result:  string 009daef2-c519-45e0-8e4a-743ea74f2a59
    return result;
  };

  Act.remoteMethod('patchActById', {
    http: {
      path: '/:id_act',
      verb: 'PATCH',
    },
    accepts: [{
      arg: 'id_act',
      type: 'string',
    }, {
      arg: 'act',
      type: 'Object',
      required: true,
      http: {source: 'body'}
    }],
    returns: {
      arg: 'act',
      type: 'string',
      root: true,
    }
  }

我希望这个结果"009daef2-c519-45e0-8e4a-743ea74f2a59"

但是我得到的这种对象巫婆是我期望转换后的字符串。 关于文档,我不知道如何以及为什么

{
  "0": "0",
  "1": "0",
  "2": "9",
  "3": "d",
  "4": "a",
  "5": "e",
  "6": "f",
  "7": "2",
  "8": "-",
  "9": "c",
  "10": "5",
  "11": "1",
  "12": "9",
  "13": "-",
  "14": "4",
  "15": "5",
  "16": "e",
  "17": "0",
  "18": "-",
  "19": "8",
  "20": "e",
  "21": "4",
  "22": "a",
  "23": "-",
  "24": "7",
  "25": "4",
  "26": "3",
  "27": "e",
  "28": "a",
  "29": "7",
  "30": "4",
  "31": "f",
  "32": "2",
  "33": "a",
  "34": "5",
  "35": "0"
}

非常感谢您的宝贵帮助

1 个答案:

答案 0 :(得分:2)

尝试这样

  Act.patchActById = async(idAct, act, cb) => {
    const update = act.__data;
    const result = await Act.updateActByRestInAnotherService(idAct, update);
    return cb(null,result);
  };