Skip to content

Commit

Permalink
#737: filter queries with Status=Inactive which are deleted already a…
Browse files Browse the repository at this point in the history
…nd only accessible via SOAP
  • Loading branch information
JoernBerkefeld committed Feb 13, 2023
1 parent 1773abd commit 2eb2aa7
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions lib/metadataTypes/Query.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const TYPE = require('../../types/mcdev.d');
const Util = require('../util/util');
const MetadataType = require('./MetadataType');
const File = require('../util/file');
const cache = require('../util/cache');
Expand Down Expand Up @@ -32,7 +33,16 @@ class Query extends MetadataType {
*/
static async retrieve(retrieveDir, _, __, key) {
await File.initPrettier('sql');
const objectId = key ? await this._getObjectIdForSingleRetrieve(key) : null;
let objectId = null;
if (key) {
objectId = await this._getObjectIdForSingleRetrieve(key);
if (!objectId) {
// avoid running the rest request below by returning early
Util.logger.info(`Downloaded: ${this.definition.type} (0) - Key: ${key}`);
return { metadata: {}, type: this.definition.type };
}
}

return super.retrieveREST(
retrieveDir,
'/automation/v1/queries/' + (objectId || ''),
Expand All @@ -51,9 +61,17 @@ class Query extends MetadataType {
static async _getObjectIdForSingleRetrieve(key) {
const response = await this.client.soap.retrieve('QueryDefinition', ['ObjectID'], {
filter: {
leftOperand: 'CustomerKey',
operator: 'equals',
rightOperand: key,
leftOperand: {
leftOperand: 'CustomerKey',
operator: 'equals',
rightOperand: key,
},
operator: 'AND',
rightOperand: {
leftOperand: 'Status',
operator: 'equals',
rightOperand: 'Active',
},
},
});
return response?.Results?.length ? response.Results[0].ObjectID : null;
Expand Down Expand Up @@ -352,6 +370,10 @@ class Query extends MetadataType {
*/
static async deleteByKey(customerKey) {
const objectId = customerKey ? await this._getObjectIdForSingleRetrieve(customerKey) : null;
if (!objectId) {
Util.logger.error(`- query not found`);
return false;
}
return super.deleteByKeyREST('/automation/v1/queries/' + objectId, customerKey);
}
/**
Expand Down

0 comments on commit 2eb2aa7

Please sign in to comment.