@@ -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