Skip to content

New Components - picqer #17044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions components/picqer/actions/add-order-comment/add-order-comment.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import picqer from "../../picqer.app.mjs";

export default {
key: "picqer-add-order-comment",
name: "Add Comment To Order",
description: "Add a comment to an order in Picqer. [See the documentation](https://picqer.com/en/api/comments#adding-comments-to-an-order)",
version: "0.0.1",
type: "action",
props: {
picqer,
orderId: {
propDefinition: [
picqer,
"orderId",
],
},
body: {
propDefinition: [
picqer,
"commentBody",
],
},
showAtRelated: {
propDefinition: [
picqer,
"showAtRelated",
],
},
isVisibleFulfillment: {
propDefinition: [
picqer,
"isVisibleFulfillment",
],
},
},
async run({ $ }) {
const response = await this.picqer.addOrderComment({
$,
orderId: this.orderId,
data: {
body: this.body,
show_at_related: this.showAtRelated,
is_visible_fulfilment: this.isVisibleFulfillment,
},
});
Comment on lines +37 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid sending undefined fields to the API

If showAtRelated or isVisibleFulfillment are left empty, they’re transmitted as null/undefined, which some APIs reject. Build the payload conditionally:

-      data: {
-        body: this.body,
-        show_at_related: this.showAtRelated,
-        is_visible_fulfilment: this.isVisibleFulfillment,
-      },
+      data: (() => {
+        const data = { body: this.body };
+        if (this.showAtRelated !== undefined)
+          data.show_at_related = this.showAtRelated;
+        if (this.isVisibleFulfillment !== undefined)
+          data.is_visible_fulfilment = this.isVisibleFulfillment;
+        return data;
+      })(),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const response = await this.picqer.addOrderComment({
$,
orderId: this.orderId,
data: {
body: this.body,
show_at_related: this.showAtRelated,
is_visible_fulfilment: this.isVisibleFulfillment,
},
});
const response = await this.picqer.addOrderComment({
$,
orderId: this.orderId,
data: (() => {
const data = { body: this.body };
if (this.showAtRelated !== undefined)
data.show_at_related = this.showAtRelated;
if (this.isVisibleFulfillment !== undefined)
data.is_visible_fulfilment = this.isVisibleFulfillment;
return data;
})(),
});
🤖 Prompt for AI Agents
In components/picqer/actions/add-order-comment/add-order-comment.mjs around
lines 37 to 45, the payload sent to the API includes fields showAtRelated and
isVisibleFulfillment even when they are undefined, which can cause API
rejection. Modify the code to conditionally add these fields to the data object
only if they have defined values, ensuring no undefined or null fields are sent
in the request.


$.export("$summary", `Successfully added comment to order ${this.orderId}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import picqer from "../../picqer.app.mjs";

export default {
key: "picqer-add-return-comment",
name: "Add Comment To Return",
description: "Add a comment to a return in Picqer. [See the documentation](https://picqer.com/en/api/comments#add-a-comment-to-an-return)",
version: "0.0.1",
type: "action",
props: {
picqer,
returnId: {
propDefinition: [
picqer,
"returnId",
],
},
body: {
propDefinition: [
picqer,
"commentBody",
],
},
showAtRelated: {
propDefinition: [
picqer,
"showAtRelated",
],
},
isVisibleFulfillment: {
propDefinition: [
picqer,
"isVisibleFulfillment",
],
},
},
async run({ $ }) {
const response = await this.picqer.addReturnComment({
$,
returnId: this.returnId,
data: {
body: this.body,
show_at_related: this.showAtRelated,
is_visible_fulfilment: this.isVisibleFulfillment,
},
});
Comment on lines +36 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid sending undefined in request payload

If showAtRelated / isVisibleFulfillment are left blank, the current body transmits null/undefined, which Picqer may reject.

- data: {
-   body: this.body,
-   show_at_related: this.showAtRelated,
-   is_visible_fulfilment: this.isVisibleFulfillment,
- },
+ data: {
+   body: this.body,
+   ...(this.showAtRelated !== undefined && { show_at_related: this.showAtRelated }),
+   ...(this.isVisibleFulfillment !== undefined && { is_visible_fulfilment: this.isVisibleFulfillment }),
+ },

Keeps the payload minimal and complies with API expectations.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async run({ $ }) {
const response = await this.picqer.addReturnComment({
$,
returnId: this.returnId,
data: {
body: this.body,
show_at_related: this.showAtRelated,
is_visible_fulfilment: this.isVisibleFulfillment,
},
});
async run({ $ }) {
const response = await this.picqer.addReturnComment({
$,
returnId: this.returnId,
data: {
body: this.body,
...(this.showAtRelated !== undefined && { show_at_related: this.showAtRelated }),
...(this.isVisibleFulfillment !== undefined && { is_visible_fulfilment: this.isVisibleFulfillment }),
},
});
🤖 Prompt for AI Agents
In components/picqer/actions/add-return-comment/add-return-comment.mjs around
lines 36 to 45, the request payload includes properties show_at_related and
is_visible_fulfilment even when their values are undefined or null, which may
cause the Picqer API to reject the request. Modify the code to only include
these properties in the data object if their corresponding values (showAtRelated
and isVisibleFulfillment) are defined, thereby keeping the payload minimal and
compliant with API expectations.


$.export("$summary", `Successfully added comment to return ${this.returnId}`);
return response;
},
};
Loading
Loading