Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit 0a2f26f

Browse files
run build
1 parent 9305867 commit 0a2f26f

File tree

1 file changed

+19
-37
lines changed

1 file changed

+19
-37
lines changed

lib/Adaptor.js

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ Object.defineProperty(exports, "http", {
8282

8383
var _axios = _interopRequireDefault(require("axios"));
8484

85-
var _languageCommon = require("@openfn/language-common");
86-
8785
var _lodash = require("lodash");
8886

87+
var _languageCommon = require("@openfn/language-common");
88+
8989
var _Utils = require("./Utils");
9090

9191
var _Client = require("./Client");
@@ -702,50 +702,32 @@ function patch(resourceType, path, data, options = {}, callback = false) {
702702
* @example <caption>a tracked entity instance</caption>
703703
* destroy('trackedEntityInstances', 'LcRd6Nyaq7T');
704704
*/
705-
// TODO: @Elias, can this be implemented using the same pattern as update but without data?
706705

707706

708-
function destroy(resourceType, path, data, options = {}, callback = false) {
707+
function destroy(resourceType, path, data = null, options = {}, callback = false) {
709708
return state => {
710-
var _options$operationNam, _options, _options$responseType, _options2, _queryParams, _queryParams2, _options$apiVersion, _options3, _CONTENT_TYPES$respon;
711-
709+
console.log('Preparing destroy operation...');
712710
resourceType = (0, _languageCommon.expandReferences)(resourceType)(state);
713711
path = (0, _languageCommon.expandReferences)(path)(state);
714-
const body = (0, _languageCommon.expandReferences)(data)(state);
715-
params = (0, _languageCommon.expandReferences)(params)(state);
712+
data = (0, _languageCommon.expandReferences)(data)(state);
716713
options = (0, _languageCommon.expandReferences)(options)(state);
717-
const operationName = (_options$operationNam = (_options = options) === null || _options === void 0 ? void 0 : _options.operationName) !== null && _options$operationNam !== void 0 ? _options$operationNam : 'delete';
718714
const {
719-
username,
720-
password,
721-
hostUrl
722-
} = state.configuration;
723-
const responseType = (_options$responseType = (_options2 = options) === null || _options2 === void 0 ? void 0 : _options2.responseType) !== null && _options$responseType !== void 0 ? _options$responseType : 'json';
724-
let queryParams = params;
725-
const filters = (_queryParams = queryParams) === null || _queryParams === void 0 ? void 0 : _queryParams.filters;
726-
(_queryParams2 = queryParams) === null || _queryParams2 === void 0 ? true : delete _queryParams2.filters;
727-
queryParams = new URLSearchParams(queryParams);
728-
filters === null || filters === void 0 ? void 0 : filters.map(f => queryParams.append('filter', f));
729-
const apiVersion = (_options$apiVersion = (_options3 = options) === null || _options3 === void 0 ? void 0 : _options3.apiVersion) !== null && _options$apiVersion !== void 0 ? _options$apiVersion : state.configuration.apiVersion;
730-
const headers = {
731-
Accept: (_CONTENT_TYPES$respon = _Utils.CONTENT_TYPES[responseType]) !== null && _CONTENT_TYPES$respon !== void 0 ? _CONTENT_TYPES$respon : 'application/json'
732-
};
733-
const url = (0, _Utils.buildUrl)('/' + resourceType + '/' + path, hostUrl, apiVersion);
734-
return _axios.default.request({
735-
method: 'DELETE',
736-
url,
737-
auth: {
738-
username,
739-
password
740-
},
741-
params: queryParams,
742-
data: body,
743-
headers
715+
params,
716+
requestConfig
717+
} = options;
718+
const {
719+
configuration
720+
} = state;
721+
return (0, _Client.request)({
722+
method: 'delete',
723+
url: (0, _Utils.generateUrl)(configuration, options, resourceType, path),
724+
params,
725+
data,
726+
...requestConfig
744727
}).then(result => {
745-
_Utils.Log.success(`${operationName} succeeded. DELETED ${resourceType}.\nSummary:\n${(0, _Utils.prettyJson)(result.data)}`);
728+
_Utils.Log.success(`Deleted ${resourceType} at ${path}`);
746729

747-
if (callback) return callback((0, _languageCommon.composeNextState)(state, result.data));
748-
return (0, _languageCommon.composeNextState)(state, result.data);
730+
return (0, _Utils.handleResponse)(result, state, callback);
749731
});
750732
};
751733
}

0 commit comments

Comments
 (0)