Skip to content

Commit

Permalink
#984: moved type specific stuff into child class
Browse files Browse the repository at this point in the history
  • Loading branch information
phjulia committed Aug 27, 2023
1 parent 3023492 commit 9abe1e5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
17 changes: 17 additions & 0 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3086,6 +3086,7 @@ ImportFile MetadataType
* [.preDeployTasks(metadata)](#ImportFile.preDeployTasks) ⇒ <code>Promise</code>
* [.getKeysToSetNotifications(metadataMap)](#ImportFile.getKeysToSetNotifications) ⇒ <code>Array.&lt;string&gt;</code>
* [.parseMetadata(metadata)](#ImportFile.parseMetadata) ⇒ <code>TYPE.MetadataTypeItem</code>
* [.createOrUpdate(metadataMap, metadataKey, hasError, metadataToUpdate, metadataToCreate)](#ImportFile.createOrUpdate) ⇒ <code>&#x27;create&#x27;</code> \| <code>&#x27;update&#x27;</code> \| <code>&#x27;skip&#x27;</code>

<a name="ImportFile.retrieve"></a>

Expand Down Expand Up @@ -3197,6 +3198,22 @@ parses retrieved Metadata before saving
| --- | --- | --- |
| metadata | <code>TYPE.MetadataTypeItem</code> | a single import definition |

<a name="ImportFile.createOrUpdate"></a>

### ImportFile.createOrUpdate(metadataMap, metadataKey, hasError, metadataToUpdate, metadataToCreate) ⇒ <code>&#x27;create&#x27;</code> \| <code>&#x27;update&#x27;</code> \| <code>&#x27;skip&#x27;</code>
helper for [upsert](#MetadataType.upsert)

**Kind**: static method of [<code>ImportFile</code>](#ImportFile)
**Returns**: <code>&#x27;create&#x27;</code> \| <code>&#x27;update&#x27;</code> \| <code>&#x27;skip&#x27;</code> - action to take

| Param | Type | Description |
| --- | --- | --- |
| metadataMap | <code>TYPE.MetadataTypeMap</code> | list of metadata |
| metadataKey | <code>string</code> | key of item we are looking at |
| hasError | <code>boolean</code> | error flag from previous code |
| metadataToUpdate | <code>Array.&lt;TYPE.MetadataTypeItemDiff&gt;</code> | list of items to update |
| metadataToCreate | <code>Array.&lt;TYPE.MetadataTypeItem&gt;</code> | list of items to create |

<a name="Journey"></a>

## Journey ⇐ [<code>MetadataType</code>](#MetadataType)
Expand Down
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ yargs
type: 'string',
group: 'Options for updateNotifications:',
describe:
"remove notification email addresses and/or notes. Possible options: 'all', 'errorEmail', 'completionEmail', 'notes'",
"remove notification email addresses and/or notes. Possible options: 'all', 'errorEmail', 'completionEmail', 'notes' for automation. For the rest of types any value would do (true/all/etc.)",

This comment has been minimized.

Copy link
@JoernBerkefeld

JoernBerkefeld Aug 28, 2023

Contributor

did this find its way into the documentation update?

})
.option('like', {
type: 'string',
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ class Mcdev {
) {
// if no options were provided there is nothing to update
Util.logger.error(`No email addresses, run notes or a clear option was provided`);
return [];
}

return await this.#runMethod('updateNotifications', businessUnit, selectedType, keys);
Expand Down
27 changes: 27 additions & 0 deletions lib/metadataTypes/ImportFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,33 @@ class ImportFile extends MetadataType {
delete metadata.updateTypeId;
return metadata;
}
/**
* helper for {@link MetadataType.upsert}
*
* @param {TYPE.MetadataTypeMap} metadataMap list of metadata
* @param {string} metadataKey key of item we are looking at
* @param {boolean} hasError error flag from previous code
* @param {TYPE.MetadataTypeItemDiff[]} metadataToUpdate list of items to update
* @param {TYPE.MetadataTypeItem[]} metadataToCreate list of items to create
* @returns {'create' | 'update' | 'skip'} action to take
*/
static createOrUpdate(metadataMap, metadataKey, hasError, metadataToUpdate, metadataToCreate) {
if (Util.OPTIONS.clear) {
metadataMap[metadataKey].sendEmailNotification = false;
metadataMap[metadataKey].notificationEmailAddress = '';
} else if (Util.OPTIONS.completionEmail) {
metadataMap[metadataKey].sendEmailNotification = true;
metadataMap[metadataKey].notificationEmailAddress = Util.OPTIONS.completionEmail;
}
const createOrUpdateAction = super.createOrUpdate(
metadataMap,
metadataKey,
hasError,
metadataToUpdate,
metadataToCreate
);
return createOrUpdateAction;

This comment has been minimized.

Copy link
@JoernBerkefeld

JoernBerkefeld Aug 28, 2023

Contributor

if your logic can run BEFORE the super.createOrUpdate, there is no need to save its return value to a variable. instead, return it directly please

}
}

// Assign definition to static attributes
Expand Down
7 changes: 0 additions & 7 deletions lib/metadataTypes/MetadataType.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,6 @@ class MetadataType {
if (!this.hasChanged(cachedVersion, metadataMap[metadataKey])) {
hasError = true;
}
if (Util.OPTIONS.clear) {
metadataMap[metadataKey].sendEmailNotification = false;
metadataMap[metadataKey].notificationEmailAddress = '';
} else if (Util.OPTIONS.completionEmail) {
metadataMap[metadataKey].sendEmailNotification = true;
metadataMap[metadataKey].notificationEmailAddress = Util.OPTIONS.completionEmail;
}
if (Util.OPTIONS.changeKeyField) {
if (this.definition.keyField == this.definition.idField) {
Util.logger.error(
Expand Down

0 comments on commit 9abe1e5

Please sign in to comment.