From b4c7f1bd348760a27d93a25e1686dc567d3eb5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Tue, 7 Mar 2023 21:34:51 +0100 Subject: [PATCH] #789: add support to update mobileMessage --- docs/dist/documentation.md | 14 +-- lib/metadataTypes/Interaction.js | 2 +- lib/metadataTypes/MetadataType.js | 9 +- lib/metadataTypes/MobileMessage.js | 4 +- .../definitions/MobileMessage.definition.js | 104 +++++++++--------- 5 files changed, 67 insertions(+), 66 deletions(-) diff --git a/docs/dist/documentation.md b/docs/dist/documentation.md index d1960589f..bbb7eaa9b 100644 --- a/docs/dist/documentation.md +++ b/docs/dist/documentation.md @@ -3178,7 +3178,7 @@ Provides default functionality that can be overwritten by child metadata type cl * [.createOrUpdate(metadata, metadataKey, hasError, metadataToUpdate, metadataToCreate)](#MetadataType.createOrUpdate) ⇒ void * [.createREST(metadataEntry, uri)](#MetadataType.createREST) ⇒ Promise.<object> \| null * [.createSOAP(metadataEntry, [overrideType], [handleOutside])](#MetadataType.createSOAP) ⇒ Promise.<object> \| null - * [.updateREST(metadataEntry, uri, [usePut])](#MetadataType.updateREST) ⇒ Promise.<object> \| null + * [.updateREST(metadataEntry, uri, [httpMethod])](#MetadataType.updateREST) ⇒ Promise.<object> \| null * [.updateSOAP(metadataEntry, [overrideType], [handleOutside])](#MetadataType.updateSOAP) ⇒ Promise.<object> \| null * [._handleSOAPErrors(ex, msg, [metadataEntry], [handleOutside])](#MetadataType._handleSOAPErrors) * [.getSOAPErrorMsg(ex)](#MetadataType.getSOAPErrorMsg) ⇒ string @@ -3510,17 +3510,17 @@ Creates a single metadata entry via fuel-soap (generic lib not wrapper) -### MetadataType.updateREST(metadataEntry, uri, [usePut]) ⇒ Promise.<object> \| null +### MetadataType.updateREST(metadataEntry, uri, [httpMethod]) ⇒ Promise.<object> \| null Updates a single metadata entry via REST **Kind**: static method of [MetadataType](#MetadataType) **Returns**: Promise.<object> \| null - Promise of API response or null in case of an error -| Param | Type | Description | -| --- | --- | --- | -| metadataEntry | TYPE.MetadataTypeItem | a single metadata Entry | -| uri | string | rest endpoint for PATCH | -| [usePut] | boolean | some update requests require PUT instead of PATCH | +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| metadataEntry | TYPE.MetadataTypeItem | | a single metadata Entry | +| uri | string | | rest endpoint for PATCH | +| [httpMethod] | 'patch' \| 'post' \| 'put' | 'patch' | defaults to 'patch'; some update requests require PUT instead of PATCH | diff --git a/lib/metadataTypes/Interaction.js b/lib/metadataTypes/Interaction.js index eaca3e6f8..18a9e0860 100644 --- a/lib/metadataTypes/Interaction.js +++ b/lib/metadataTypes/Interaction.js @@ -231,7 +231,7 @@ class Interaction extends MetadataType { * @returns {Promise} Promise */ static update(metadata) { - return super.updateREST(metadata, '/interaction/v1/interactions/', true); + return super.updateREST(metadata, '/interaction/v1/interactions/', 'put'); } /** diff --git a/lib/metadataTypes/MetadataType.js b/lib/metadataTypes/MetadataType.js index 17fd2a462..bef1999e2 100644 --- a/lib/metadataTypes/MetadataType.js +++ b/lib/metadataTypes/MetadataType.js @@ -671,15 +671,14 @@ class MetadataType { * * @param {TYPE.MetadataTypeItem} metadataEntry a single metadata Entry * @param {string} uri rest endpoint for PATCH - * @param {boolean} [usePut] some update requests require PUT instead of PATCH + * @param {'patch'|'post'|'put'} [httpMethod='patch'] defaults to 'patch'; some update requests require PUT instead of PATCH * @returns {Promise. | null} Promise of API response or null in case of an error */ - static async updateREST(metadataEntry, uri, usePut) { + static async updateREST(metadataEntry, uri, httpMethod = 'patch') { + Util.logger.info('uri: ' + uri); this.removeNotUpdateableFields(metadataEntry); try { - const response = usePut - ? await this.client.rest.put(uri, metadataEntry) - : await this.client.rest.patch(uri, metadataEntry); + const response = await this.client.rest[httpMethod](uri, metadataEntry); this.checkForErrors(response); // some times, e.g. automation dont return a key in their update response and hence we need to fall back to name Util.logger.info( diff --git a/lib/metadataTypes/MobileMessage.js b/lib/metadataTypes/MobileMessage.js index de39a9ba4..86215cc3d 100644 --- a/lib/metadataTypes/MobileMessage.js +++ b/lib/metadataTypes/MobileMessage.js @@ -150,9 +150,11 @@ class MobileMessage extends MetadataType { static update(metadata) { return super.updateREST( metadata, - '/legacy/v1/beta/mobile/message/' + metadata[this.definition.keyField] + '/legacy/v1/beta/mobile/message/' + metadata[this.definition.keyField], + 'post' ); } + /** * Creates a single Event Definition * diff --git a/lib/metadataTypes/definitions/MobileMessage.definition.js b/lib/metadataTypes/definitions/MobileMessage.definition.js index 144ec6b66..156170d10 100644 --- a/lib/metadataTypes/definitions/MobileMessage.definition.js +++ b/lib/metadataTypes/definitions/MobileMessage.definition.js @@ -64,163 +64,163 @@ module.exports = { }, lastUpdated: { isCreateable: false, - isUpdateable: false, + isUpdateable: true, retrieving: true, template: false, }, 'code.code': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: true, template: true, }, 'code.id': { isCreateable: true, - isUpdateable: false, + isUpdateable: true, retrieving: false, template: false, }, 'code.createdDate': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.lastUpdated': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.startDate': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.endDate': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.keywordLimit': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.keywordsUsed': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.codeType': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.isShortCode': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.keywordsUsedOther': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.isGsmCharacterSetOnly': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.isMms': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.isStackIndependant': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.supportsConcatenation': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.isClientOwned': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.isOwner': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.dipSwitches': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.sendableCountries': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.countryCode': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'code.moEngineVersion': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'keyword.id': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'keyword.keyword': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: true, template: true, }, 'keyword.restriction': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'keyword.keywordType': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, }, 'keyword.isInherited': { - isCreateable: false, - isUpdateable: false, + isCreateable: true, + isUpdateable: true, retrieving: false, template: false, },