Skip to content

Commit a4e624d

Browse files
Merge pull request #54 from eversign/issue#16-document-cancellation-does-not-work
issue#16: Fix for document cancellation is not working
2 parents 9061435 + 4ce4473 commit a4e624d

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

examples/cancel_document.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
var Client = require('../index').Client;
4+
var config = require('./config');
5+
6+
var client = new Client(config.accessKey, config.businessId);
7+
8+
client.getDocumentByHash(config.documentHash).then(function(doc) {
9+
console.log(doc.getDocumentHash());
10+
11+
client.cancelDocument(doc).catch(function(err) {
12+
console.log(err)
13+
});
14+
15+
}).catch(function(err) {
16+
console.log(err)
17+
});

lib/Client.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ function Client(accessKey, businessId){
245245
};
246246

247247
/**
248-
* Deletes the specified Document. Only works on Drafts and canceled Documents
248+
* Deletes the specified Document.
249+
* Delete function can cancel or delete document, depending of parameter "type"
250+
*
251+
* If type === "cancel" we are cancelling document and there are no delete checks.
252+
* If type !== "cancel" we are allowing deletion only if document is already cancelled.
249253
*
250254
* @param {Document} document [description]
251255
* @param {String} type [description]
@@ -256,7 +260,7 @@ function Client(accessKey, businessId){
256260
if (!document.getDocumentHash()) {
257261
throw new Error('Deleting the Document requires the Document Hash');
258262
}
259-
if (!document.getIsDraft() && !document.getIsCancelled()) {
263+
if (type !== "cancel" && !document.getIsDraft() && !document.getIsCancelled()) {
260264
throw new Error('Only Drafts and cancelled Documents can be deleted');
261265
}
262266
if (document.getIsDeleted()) {
@@ -269,8 +273,8 @@ function Client(accessKey, businessId){
269273
if(type) {
270274
parameters[type] = 1;
271275
}
272-
var request = new ApiRequest("DELETE", accessKey, config.DOCUMENT_URL, undefined, $parameters);
273-
return request.startRequest().then(resolve).catch(reject);
276+
var request = new ApiRequest("DELETE", accessKey, config.DOCUMENT_URL, undefined, parameters);
277+
return request.startRequest();
274278
});
275279
};
276280

0 commit comments

Comments
 (0)