Skip to content

Commit

Permalink
feat: restore an expense
Browse files Browse the repository at this point in the history
Signed-off-by: Raúl Fernández Fernández <[email protected]>
  • Loading branch information
rfdez committed Sep 26, 2023
1 parent a37531d commit fa1c3a6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Follow the [installation guide](https://docs.n8n.io/integrations/community-nodes
- List the current user's expenses
- Create an expense (in equally split mode)
- Delete an expense
- Restore an expense

## Credentials

Expand Down
24 changes: 15 additions & 9 deletions nodes/Splitwise/ExpenseDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export const expenseOperations: INodeProperties[] = [
action: 'Create an expense',
},
{
name: 'Get Many',
value: 'getAll',
description: "List the current user's expenses",
action: 'Get many expenses',
name: 'Delete',
value: 'delete',
description: 'Delete an expense',
action: 'Delete an expense',
},
{
name: 'Get',
Expand All @@ -32,10 +32,16 @@ export const expenseOperations: INodeProperties[] = [
action: 'Get an expense',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete an expense',
action: 'Delete an expense',
name: 'Get Many',
value: 'getAll',
description: "List the current user's expenses",
action: 'Get many expenses',
},
{
name: 'Restore',
value: 'restore',
description: 'Restore an expense',
action: 'Restore an expense',
},
],
},
Expand All @@ -52,7 +58,7 @@ const sharedExpenseFields: INodeProperties[] = [
displayOptions: {
show: {
resource: ['expense'],
operation: ['get', 'delete'],
operation: ['get', 'delete', 'restore'],
},
},
typeOptions: {
Expand Down
18 changes: 18 additions & 0 deletions nodes/Splitwise/Splitwise.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,24 @@ export class Splitwise implements INodeType {
throw new NodeOperationError(this.getNode(), errorMessage, { itemIndex: i });
}
}

if (operation === 'restore') {
const id = this.getNodeParameter('id', i) as number;

responseData = await splitwiseApiRequest.call(
this,
'POST',
`/undelete_expense/${id}`,
{},
);

if (responseData.error || responseData.errors?.base?.length) {
const errorMessage = responseData.error
? responseData.error
: responseData.errors.base[0];
throw new NodeOperationError(this.getNode(), errorMessage, { itemIndex: i });
}
}
}

returnData.push(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rfdez/n8n-nodes-splitwise",
"version": "0.4.0",
"version": "0.5.0",
"description": "n8n community node to consume the Splitwise API",
"keywords": [
"n8n-community-node-package"
Expand Down

0 comments on commit fa1c3a6

Please sign in to comment.