コネクタ使ったAPIの編集

コネクタを利用するAPIの実装』で、コネクタを利用するAPIの実装をしてみました。 実際の業務では、コネクタからのレスポンスをそのまま使わずに、整形してから返すニーズが多いため、ここでは、コネクタのレスポンス結果を編集してみます。

エンドポイント GET /incidents/{id}

エンドポイント「GET /incidents/{id}」では、SOAPコネクタのエンドポイント「GetIncidentById」を呼び出します。

GET /incidents/{id} の変更前

service.get('/mobile/custom/FIF_IncidentReport_xx/incidents/:id', function(req,res) {
  req.oracleMobile.connectors.FIF_SoapWS_xx.post(
    'GetIncidentById',
    {Body: {GetIncidentById: {'IncidentId': req.params.id}}},
    {inType: "json"}
  ).then(
    function (success) {
      var responsePayload = JSON.parse(success.result);
      if (responsePayload.Body.GetIncidentByIdResponse == null) {
        res.send(404,
          'The requested resource could not be found ' +
          'but may be available again in the future');
      }
      res.send(success.statusCode, responsePayload);
    },
    function (failure) {
      res.send(500, failure.error);
    }
  );
});

GET /incidents/{id} の変更後

service.get('/mobile/custom/FIF_IncidentReport_xx/incidents/:id', function(req,res) {
  req.oracleMobile.connectors.FIF_SoapWS_3d.post(
    'GetIncidentById',
    {Body: {GetIncidentById: {'IncidentId': req.params.id}}},
    {inType: "json"}
  ).then(
    function (success) {
      var responsePayload = JSON.parse(success.result);
      if (responsePayload.Body.GetIncidentByIdResponse == null) {
        res.send(404,
          'The requested resource could not be found ' +
          'but may be available again in the future');
      } else {
          var incident = responsePayload.Body.GetIncidentByIdResponse.Incident;

          var responsePayloadNew = {};

          responsePayloadNew.id = incident.Id;
          responsePayloadNew.status = incident.Status;
          responsePayloadNew.priority = incident.Priority;
          responsePayloadNew.notes = incident.Notes;
          responsePayloadNew.createdon = incident.Date;
          responsePayloadNew.imageLink = incident.ImageLink;
          responsePayloadNew.technicianAssigned = incident.TechnicianAssigned;

          res.send(success.statusCode, responsePayloadNew);
      }
    },
    function (failure) {
      res.send(500, failure.error);
    }
  );
});

備考: C:\HOL\AMCe\code\IncidentGETbyIDUpdate.txt をコピーすることも可能です。

results matching ""

    No results matching ""