UNPKG

route4me-node

Version:

Access Route4Me's logistics-as-a-service API using our Node.js SDK

98 lines (84 loc) 3.07 kB
"use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var utils = require("./../utils"); /** * Notes facility * * @category Notes */ var Notes = function () { /** * Constructor * * @see {@link https://route4me.io/docs/#tracking} * @since 0.1.9 * @private * * @param {RequestManager} requestManager - Request Manager * @return {Notes} - Notes facility */ function Notes(requestManager) { _classCallCheck(this, Notes); this.r = requestManager; } /** * Add Route Notes * * * ADD Notes to a route. * * ADD Notes to a route using file uploading. * * @see {@link https://route4me.io/docs/#add-route-notes} * @see {@link https://route4me.io/docs/#add-a-note-file} * @since 0.1.9 * * @todo TODO: improve documentation about file attaching * @todo TODO: parse response (it is the Note wrapped into an additional object) * * @param {Object} data - Note Data * @param {string} data.routeId - Route ID * @param {number} data.addressId - Address ID * @param {number} data.deviceLatitude - Device latitude * @param {number} data.deviceLongitude - Device longitude * @param {string} data.deviceType - Device type * @param {string} data.note - NOTE text * @param {blob} data.file - FILE to use as a note * @param {string} data.type - FILE/NOTE type. One of `DRIVER_IMG`, * `VEHICLE_IMG`, `ADDRESS_IMG`, `CSV_FILE`, `XLS_FILE`, `ANY_FILE` * @param {module:route4me-node~RequestCallback<jsonschema:Notes.NoteCreateResponse>} * [callback] */ _createClass(Notes, [{ key: "create", value: function create(data, callback) { var qs = utils.mapObject(data, { "routeId": "route_id", "addressId": "address_id", "deviceLatitude": "dev_lat", "deviceLongitude": "dev_lng", "deviceType": "device_type" }); // ??? var noteType = data.type || "dropoff"; qs["strUpdateType"] = noteType; var body = void 0; if (data.note) { body = { // "strUpdateType": noteType, // ALREADY passed via QS "strNoteContents": data.note }; } else { body = data.file; } return this.r._makeRequest({ method: "POST", path: "/actions/addroutenotes.php", qs, body, validationContext: "Notes.NoteCreateResponse" }, callback); } }]); return Notes; }(); module.exports = Notes;