From 64a90f6c50a5d68906e371e045ea3cf116347785 Mon Sep 17 00:00:00 2001 From: Benjamin Piouffle Date: Tue, 30 Jan 2024 15:47:48 +0100 Subject: [PATCH] enhancement(TransactionsCSV): split accounting categories --- src/server/controllers/account-transactions.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/server/controllers/account-transactions.js b/src/server/controllers/account-transactions.js index 198fe0c8..e87a6f9e 100644 --- a/src/server/controllers/account-transactions.js +++ b/src/server/controllers/account-transactions.js @@ -248,16 +248,9 @@ const formatAccountName = (account) => { } }; -const formatAccountingCategory = (accountingCategory) => { - if (!accountingCategory) { - return ''; - } else { - return `${accountingCategory.code} - ${accountingCategory.name}`; - } -}; - const csvMapping = { - accountingCategory: (t) => formatAccountingCategory(get(t, 'expense.accountingCategory')), + accountingCategoryCode: (t) => get(t, 'expense.accountingCategory.code') || '', + accountingCategoryName: (t) => get(t, 'expense.accountingCategory.name') || '', date: (t) => moment.utc(t.createdAt).format('YYYY-MM-DD'), datetime: (t) => moment.utc(t.createdAt).format('YYYY-MM-DDTHH:mm:ss'), id: 'id', @@ -529,7 +522,7 @@ const accountTransactions = async (req, res) => { const fetchAll = variables.offset ? false : parseToBooleanDefaultFalse(req.query.fetchAll); // Add fields info to the query, to prevent fetching what's not needed - variables.hasAccountingCategoryField = fields.includes('accountingCategory'); + variables.hasAccountingCategoryField = fields.some((field) => field.startsWith('accountingCategory')); try { // Forward Api Key or Authorization header