Skip to content

Commit e8cc937

Browse files
committed
Refactor Encharge component actions for improved error handling and output formatting
- Updated the return statement in the tags processing to use a ternary operator for clarity. - Removed unused additionalFields from the add-or-update-person action. - Enhanced the summary message in the add-or-update-person action to conditionally include the email. - Added validation in the archive-person action to ensure either user ID or email is provided. - Modified the remove-tags action to handle tags as an array for consistent processing.
1 parent 2aa0c23 commit e8cc937

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

components/encharge/actions/add-or-update-person/add-or-update-person.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export default {
5555
email: this.email,
5656
phone: this.phone,
5757
id: this.userId,
58-
additionalFields: this.additionalFields,
5958
...parsedAdditionalFields,
6059
},
6160
];
@@ -67,7 +66,9 @@ export default {
6766

6867
$.export("$summary", `Successfully ${this.userId
6968
? "updated"
70-
: "added"} person with email ${this.email}`);
69+
: "added"} person${this.email
70+
? ` with email ${this.email}`
71+
: ""}`);
7172
return response;
7273
},
7374
};

components/encharge/actions/archive-person/archive-person.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export default {
3535
},
3636
},
3737
async run({ $ }) {
38+
if (!this.userId && !this.email) {
39+
throw new Error("You must provide either a user ID or an email.");
40+
}
3841
if (this.userId && this.email) {
3942
throw new Error("You must provide either a user ID or an email, not both.");
4043
}

components/encharge/actions/remove-tags/remove-tags.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,20 @@ export default {
3232
},
3333
},
3434
async run({ $ }) {
35+
const tags = parseObject(this.tags);
36+
const tagsArray = Array.isArray(tags)
37+
? tags
38+
: [
39+
tags,
40+
];
3541
const response = await this.app.removeTag({
3642
$,
3743
data: {
38-
tag: parseObject(this.tags).join(","),
44+
tag: tagsArray.join(","),
3945
id: this.userId,
4046
},
4147
});
42-
$.export("$summary", `Successfully removed ${this.tags.length} tag${this.tags.length > 1
48+
$.export("$summary", `Successfully removed ${tagsArray.length} tag${tagsArray.length > 1
4349
? "s"
4450
: ""} from person with ID ${this.userId}`);
4551
return response;

components/encharge/encharge.app.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export default {
4545
],
4646
},
4747
});
48-
return tags && tags.split(",") || [];
48+
return tags
49+
? tags.split(",")
50+
: [];
4951
},
5052
},
5153
},

components/encharge/sources/tag-removed-from-person-instant/tag-removed-from-person-instant.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default {
2424
},
2525
generateMeta({
2626
endUserData: [
27-
id,
27+
{ id },
2828
],
2929
}) {
3030
return {

0 commit comments

Comments
 (0)