Skip to content

Commit fa90d15

Browse files
committed
ES Lint Fixes for Download PDF action
1 parent b87879d commit fa90d15

File tree

1 file changed

+59
-55
lines changed

1 file changed

+59
-55
lines changed
Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,64 @@
11
const quickbooks = require("../../quickbooks.app");
2-
const fs = require('fs')
2+
const fs = require("fs");
33

44
module.exports = {
5-
name: 'Download PDF',
6-
description: 'Download an invoice, bill, purchase order, etc. as a PDF and save it in the temporary file system for use in a later step.',
7-
key: 'download_pdf',
8-
version: '0.1.3',
9-
type: 'action',
10-
props: {
11-
quickbooks,
12-
entity: {
13-
type: 'string',
14-
label: 'Document Type',
15-
options: [
16-
"CreditMemo",
17-
"Estimate",
18-
"Invoice",
19-
"Payment",
20-
"PurchaseOrder",
21-
"RefundReceipt",
22-
"SalesReceipt",
23-
],
24-
},
25-
id: {
26-
type: 'string',
27-
label: 'Record Id',
28-
},
29-
file_name: {
30-
type: 'string',
31-
label: 'File Name (Optional)',
32-
optional: true,
33-
},
34-
},
35-
methods: {
36-
async downloadPDF(entity, id, file_name){
37-
const file = await require("@pipedreamhq/platform").axios(this, {
38-
url: `https://quickbooks.api.intuit.com/v3/company/${this.quickbooks.$auth.company_id}/${entity.toLowerCase()}/${id}/pdf`,
39-
headers: {
40-
Authorization: `Bearer ${this.quickbooks.$auth.oauth_access_token}`,
41-
'accept': 'application/pdf',
42-
},
43-
responseType: 'arraybuffer',
44-
})
5+
name: "Download PDF",
6+
description: "Download an invoice, bill, purchase order, etc. as a PDF and save it in the temporary file system for use in a later step.",
7+
key: "download_pdf",
8+
version: "0.2.3",
9+
type: "action",
10+
props: {
11+
quickbooks,
12+
entity: {
13+
type: "string",
14+
label: "Document Type",
15+
description: null,
16+
options: [
17+
"CreditMemo",
18+
"Estimate",
19+
"Invoice",
20+
"Payment",
21+
"PurchaseOrder",
22+
"RefundReceipt",
23+
"SalesReceipt",
24+
],
25+
},
26+
id: {
27+
type: "string",
28+
label: "Record ID",
29+
description: null,
30+
},
31+
fileName: {
32+
type: "string",
33+
label: "File Name (Optional)",
34+
description: "If no file name is provided, the PDF will be named using the record ID, e.g. '22743.pdf'",
35+
optional: true,
36+
},
37+
},
38+
methods: {
39+
async downloadPDF(entity, id, fileName) {
40+
const file = await require("@pipedreamhq/platform").axios(this, {
41+
url: `https://quickbooks.api.intuit.com/v3/company/${this.quickbooks.$auth.company_id}/${entity.toLowerCase()}/${id}/pdf`,
42+
headers: {
43+
"Authorization": `Bearer ${this.quickbooks.$auth.oauth_access_token}`,
44+
"accept": "application/pdf",
45+
},
46+
responseType: "arraybuffer",
47+
});
4548

46-
const file_path = '/tmp/' + file_name
47-
fs.writeFileSync(file_path, file)
49+
const filePath = "/tmp/" + fileName;
50+
fs.writeFileSync(filePath, file);
51+
return filePath;
52+
},
53+
},
54+
async run({ $ }) {
55+
const fileName = this.fileName || this.id;
56+
const fileNameWithExtension = fileName.endsWith(".pdf")
57+
? fileName
58+
: fileName + ".pdf";
4859

49-
return file_path
50-
}
51-
},
52-
async run({ $ }){
53-
const file_name = this.file_name || this.id
54-
const file_name_with_extension = file_name.endsWith('.pdf') ? file_name : file_name + '.pdf'
55-
56-
const file_path = await this.downloadPDF(this.entity, this.id, file_name_with_extension)
57-
$.export('file_path', file_path)
58-
$.export('file_name', file_name_with_extension)
59-
}
60-
}
60+
const filePath = await this.downloadPDF(this.entity, this.id, fileNameWithExtension);
61+
$.export("file_path", filePath);
62+
$.export("file_name", fileNameWithExtension);
63+
},
64+
};

0 commit comments

Comments
 (0)