From 61e24da07d57c6505655f8cbdf90ef1ebacbc952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Thu, 12 Oct 2023 13:47:34 +0300 Subject: [PATCH] feat(invoice-ninja): add create product action --- .../actions/create-product/fields.ts | 114 ++++++++++++++++++ .../actions/create-product/index.ts | 52 ++++++++ .../src/apps/invoice-ninja/actions/index.ts | 3 +- .../docs/pages/apps/invoice-ninja/actions.md | 2 + 4 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/apps/invoice-ninja/actions/create-product/fields.ts create mode 100644 packages/backend/src/apps/invoice-ninja/actions/create-product/index.ts diff --git a/packages/backend/src/apps/invoice-ninja/actions/create-product/fields.ts b/packages/backend/src/apps/invoice-ninja/actions/create-product/fields.ts new file mode 100644 index 00000000..0c76196d --- /dev/null +++ b/packages/backend/src/apps/invoice-ninja/actions/create-product/fields.ts @@ -0,0 +1,114 @@ +export const fields = [ + { + label: 'Product Key', + key: 'productKey', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Notes', + key: 'notes', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Price', + key: 'price', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Quantity', + key: 'quantity', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Tax Rate 1', + key: 'taxRate1', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Tax Name 1', + key: 'taxName1', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Tax Rate 2', + key: 'taxRate2', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Tax Name 2', + key: 'taxName2', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Tax Rate 3', + key: 'taxRate3', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Tax Name 3', + key: 'taxName3', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Custom Value 1', + key: 'customValue1', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Custom Value 2', + key: 'customValue2', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Custom Value 3', + key: 'customValue3', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, + { + label: 'Custom Value 4', + key: 'customValue4', + type: 'string' as const, + required: false, + description: '', + variables: true, + }, +]; diff --git a/packages/backend/src/apps/invoice-ninja/actions/create-product/index.ts b/packages/backend/src/apps/invoice-ninja/actions/create-product/index.ts new file mode 100644 index 00000000..d84d8232 --- /dev/null +++ b/packages/backend/src/apps/invoice-ninja/actions/create-product/index.ts @@ -0,0 +1,52 @@ +import defineAction from '../../../../helpers/define-action'; +import { filterProvidedFields } from '../../common/filter-provided-fields'; +import { fields } from './fields'; + +export default defineAction({ + name: 'Create product', + key: 'createProduct', + description: 'Creates a new product.', + arguments: fields, + + async run($) { + const { + productKey, + notes, + price, + quantity, + taxRate1, + taxName1, + taxRate2, + taxName2, + taxRate3, + taxName3, + customValue1, + customValue2, + customValue3, + customValue4, + } = $.step.parameters; + + const bodyFields = { + product_key: productKey, + notes: notes, + price: price, + quantity: quantity, + tax_rate1: taxRate1, + tax_name1: taxName1, + tax_rate2: taxRate2, + tax_name2: taxName2, + tax_rate3: taxRate3, + tax_name3: taxName3, + custom_value1: customValue1, + custom_value2: customValue2, + custom_value3: customValue3, + custom_value4: customValue4, + }; + + const body = filterProvidedFields(bodyFields); + + const response = await $.http.post('/v1/products', body); + + $.setActionItem({ raw: response.data.data }); + }, +}); diff --git a/packages/backend/src/apps/invoice-ninja/actions/index.ts b/packages/backend/src/apps/invoice-ninja/actions/index.ts index 5a9dc32c..8a1bff38 100644 --- a/packages/backend/src/apps/invoice-ninja/actions/index.ts +++ b/packages/backend/src/apps/invoice-ninja/actions/index.ts @@ -1,5 +1,6 @@ import createClient from './create-client'; import createInvoice from './create-invoice'; import createPayment from './create-payment'; +import createProduct from './create-product'; -export default [createClient, createInvoice, createPayment]; +export default [createClient, createInvoice, createPayment, createProduct]; diff --git a/packages/docs/pages/apps/invoice-ninja/actions.md b/packages/docs/pages/apps/invoice-ninja/actions.md index be4e38fb..d96f5310 100644 --- a/packages/docs/pages/apps/invoice-ninja/actions.md +++ b/packages/docs/pages/apps/invoice-ninja/actions.md @@ -7,6 +7,8 @@ items: desc: Creates a new invoice. - name: Create payment desc: Creates a new payment. + - name: Create product + desc: Creates a new product. ---