'use strict';

angular.module('app')
    .factory('rgiDocumentMethodSrvc', function ($q, rgiDocumentSrvc) {
        return {
            updateDocument: function (new_doc_data) {
                var dfd = $q.defer();

                new_doc_data.$update().then(function () {
                    dfd.resolve();
                }, function (response) {
                    dfd.reject(response.data.reason);
                });
                return dfd.promise;
            },
            deleteDocument: function (documentId) {
                var
                    dfd = $q.defer(),
                    doc = new rgiDocumentSrvc();

                doc.id = documentId;

                doc.$delete().then(function (response) {
                    if(response.reason) {
                        dfd.reject(response.reason);
                    } else {
                        dfd.resolve(response);
                    }
                }, function () {
                    dfd.reject('Request Failed');
                });

                return dfd.promise;
            }
        };
    });

@@ -82,11 +82,16 @@
 on (
-$q,
+%0A       
  rgi
@@ -102,19 +102,17 @@
 mentSrvc
-) %7B
+,
 %0A       
@@ -117,84 +117,48 @@
    r
-eturn %7B%0A            updateDocument: function (new_doc_data) %7B
+giResourceProcessorSrvc
 %0A    
-  
+) %7B%0A
         
   va
@@ -157,77 +157,45 @@
     
-  var dfd = $q.defer();%0A%0A                new_doc_data.$update().then(
+return %7B%0A            updateDocument: 
 func
@@ -192,32 +192,35 @@
 ment: function (
+doc
 ) %7B%0A            
@@ -227,779 +227,215 @@
     
-    dfd.resolve();%0A                %7D, function (response) %7B%0A                    dfd.reject(response.data.reason);%0A                %7D);%0A                return dfd.promise;%0A            %7D,%0A            deleteDocument: function (documentId) %7B%0A                var%0A                    dfd = $q.defer(),%0A                    doc = new rgiDocumentSrvc();%0A%0A                doc.id = documentId;%0A%0A                do
+return rgiResourceProcessorSrvc.process(doc, '$update');%0A            %7D,%0A            deleteDocument: function (documentId) %7B%0A                return rgiResourceProcessorSrv
 c.
-$
 delete(
-).then(function (response) %7B%0A                    if(response.reason) %7B%0A                        dfd.reject(response.reason);%0A                    %7D else %7B%0A                        dfd.resolve(response);%0A                    %7D%0A                %7D, function () %7B%0A                    dfd.reject('Request Failed');%0A                %7D);%0A%0A                return dfd.promise
+rgiDocumentSrvc, documentId)
 ;%0A  

fix back-end response processing for documents