Skip to content

Commit

Permalink
Add newly added transaction filters to CSV endpoint (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavlrsn authored Apr 8, 2024
1 parent cdd1cdc commit aeb06a2
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/server/controllers/account-transactions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Parser } from '@json2csv/plainjs';
import gqlV2 from 'graphql-tag';
import { difference, get, head, intersection, pick, toUpper, trim } from 'lodash';
import { difference, get, head, intersection, isNil, pick, toUpper, trim } from 'lodash';
import moment from 'moment';

import { graphqlRequest } from '../lib/graphql';
Expand Down Expand Up @@ -182,6 +182,10 @@ const transactionsQuery = gqlV2/* GraphQL */ `
$fullDescription: Boolean
$hasAccountingCategoryField: Boolean!
$paymentMethodType: [PaymentMethodType]
$expenseType: [ExpenseType]
$expense: ExpenseReferenceInput
$order: OrderReferenceInput
$isRefund: Boolean
) {
transactions(
includeDebts: true
Expand Down Expand Up @@ -232,6 +236,10 @@ const hostTransactionsQuery = gqlV2/* GraphQL */ `
$account: [AccountReferenceInput!]
$hasAccountingCategoryField: Boolean!
$paymentMethodType: [PaymentMethodType]
$expenseType: [ExpenseType]
$expense: ExpenseReferenceInput
$order: OrderReferenceInput
$isRefund: Boolean
) {
transactions(
includeDebts: true
Expand Down Expand Up @@ -446,6 +454,10 @@ const accountTransactions = async (req, res) => {
'includeGiftCardTransactions',
'includeRegularTransactions',
'includeHost',
'expenseType',
'expenseId',
'orderId',
'isRefund',
]);
variables.limit =
// If HEAD, we only want count, so we set limit to 0
Expand Down Expand Up @@ -545,6 +557,23 @@ const accountTransactions = async (req, res) => {
variables.kind = difference(variables.kind || allKinds, ['TAX']);
}

if (variables.expenseType) {
variables.expenseType = variables.expenseType.split(',').map(toUpper).map(trim);
}

if (variables.orderId) {
variables.order = { legacyId: parseInt(variables.orderId) };
}

if (variables.expenseId) {
variables.expense = { legacyId: parseInt(variables.expenseId) };
}

// isRefund can be false but default should be undefined
if (!isNil(variables.isRefund)) {
variables.isRefund = parseToBooleanDefaultFalse(variables.isRefund);
}

if (req.query.fullDescription) {
variables.fullDescription = parseToBooleanDefaultFalse(req.query.fullDescription);
} else {
Expand Down

0 comments on commit aeb06a2

Please sign in to comment.