feat(invoice-ninja): add create product action

This commit is contained in:
Rıdvan Akca
2023-10-12 13:47:34 +03:00
parent 648511dfad
commit 61e24da07d
4 changed files with 170 additions and 1 deletions

View File

@@ -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,
},
];

View File

@@ -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 });
},
});

View File

@@ -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];

View File

@@ -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.
---
<script setup>