Skip to content

Commit

Permalink
Merge pull request #526 from ripe-tech/jc/shipment-create-issues-notes
Browse files Browse the repository at this point in the history
feat: add shipment notes & issues
  • Loading branch information
3rdvision authored Oct 18, 2023
2 parents 7059d40 + f4ca22b commit 85a3016
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added waybill and invoice creation methods to the `ShipmentAPI` - [#4853](https://github.com/ripe-tech/ripe-core/issues/4853)
* Added shipment attachment methods to the `ShipmentAPI` - [#4853](https://github.com/ripe-tech/ripe-core/issues/4853)
* Added shipment status change methods to the `ShipmentAPI` - [#4853](https://github.com/ripe-tech/ripe-core/issues/4853)
* Added shipment notes and issues methods - [ripe-pulse/#396](https://github.com/ripe-tech/ripe-pulse/issues/396)

### Changed

Expand Down
87 changes: 87 additions & 0 deletions src/js/api/shipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,93 @@ ripe.Ripe.prototype.attachmentShipmentP = function(number, attachmentId, options
});
};

/**
* Creates a note with the provided text and associates it
* with the shipment with the provided number.
*
* @param {Number} number The number of the shipment to associate a note.
* @param {String} text The note text, containing the context of the note.
* @param {Object} options An object of options to configure the request.
* @param {Function} callback Function with the result of the request.
* @returns {XMLHttpRequest} The XMLHttpRequest instance of the API request.
*/
ripe.Ripe.prototype.createNoteShipment = function(number, text, options, callback) {
callback = typeof options === "function" ? options : callback;
options = typeof options === "function" || options === undefined ? {} : options;
const url = `${this.url}shipments/${number}/notes`;
options = Object.assign(options, {
url: url,
method: "POST",
auth: true
});
options.params = options.params || {};
options.params.text = text;
options = this._build(options);
return this._cacheURL(options.url, options, callback);
};

/**
* Creates a note with the provided text and associates it
* with the shipment with the provided number.
*
* @param {Number} number The number of the shipment to associate a note.
* @param {String} text The note text, containing the context of the note.
* @param {Object} options An object of options to configure the request.
* @returns {Promise} The contents of the note instance that was created.
*/
ripe.Ripe.prototype.createNoteShipmentP = function(number, text, options) {
return new Promise((resolve, reject) => {
this.createNoteShipment(number, text, options, (result, isValid, request) => {
isValid ? resolve(result) : reject(new ripe.RemoteError(request, null, result));
});
});
};

/**
* Creates a shipment issue with the provided description, error log and severity
* and associates it with the shipment with the provided number.
*
* @param {Number} number The number of the shipment to associate an issue.
* @param {String} issue The issue name, containing the context of issue.
* @param {Object} options An object of options to configure the request.
* @param {Function} callback Function with the result of the request.
* @returns {XMLHttpRequest} The XMLHttpRequest instance of the API request.
*/
ripe.Ripe.prototype.createIssueShipment = function(number, issue, options, callback) {
callback = typeof options === "function" ? options : callback;
options = typeof options === "function" || options === undefined ? {} : options;
const url = `${this.url}shipments/${number}/issues`;
options = Object.assign(options, {
url: url,
method: "POST",
auth: true
});
options.params = options.params || {};
options.params.issue = issue;
if (options.description !== undefined) options.params.description = options.description;
if (options.severity !== undefined) options.params.severity = options.severity;
if (options.log !== undefined) options.params.log = options.log;
options = this._build(options);
return this._cacheURL(options.url, options, callback);
};

/**
* Creates a shipment issue with the provided description, error log and severity
* and associates it with the shipment with the provided number.
*
* @param {Number} number The number of the shipment to associate an issue.
* @param {String} issue The issue name, containing the context of issue.
* @param {Object} options An object of options to configure the request.
* @returns {Promise} The contents of the issue instance that was created.
*/
ripe.Ripe.prototype.createIssueShipmentP = function(number, issue, options) {
return new Promise((resolve, reject) => {
this.createIssueShipment(number, issue, options, (result, isValid, request) => {
isValid ? resolve(result) : reject(new ripe.RemoteError(request, null, result));
});
});
};

/**
* Creates a shipping waybill for the shipment with the provided number.
*
Expand Down

1 comment on commit 85a3016

@vercel
Copy link

@vercel vercel bot commented on 85a3016 Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ripe-sdk – ./

ripe-sdk-docs-csr.vercel.app
ripe-sdk-platforme.vercel.app
ripe-sdk-git-master-platforme.vercel.app

Please sign in to comment.