Skip to content

Commit

Permalink
Merge pull request #74 from afaneca/develop
Browse files Browse the repository at this point in the history
2.4.0
  • Loading branch information
afaneca committed Jun 26, 2024
2 parents 1222884 + 1fb63ec commit ae27265
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"db:seed": "prisma db seed"
},
"name": "myfin-api",
"version": "2.3.1",
"version": "2.4.0",
"description": "NodeJS API for Myfin",
"main": "src/server.js",
"devDependencies": {
Expand Down
24 changes: 10 additions & 14 deletions src/services/categoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,28 @@ const getAmountForCategoryInPeriod = async (
category_balance_credit: number;
category_balance_debit: number
}> => performDatabaseRequest(async (prismaTx) => {
/* Logger.addLog(
`Category: ${categoryId} | fromDate: ${fromDate} | toDate: ${toDate} | includeTransfers: ${includeTransfers}`); */
let accountsToExcludeListInSQL = '';

const listOfAccountsToExclude = await prismaTx.accounts.findMany({
where: {exclude_from_budgets: true},
where: { exclude_from_budgets: true },
});
accountsToExcludeListInSQL = buildSqlForExcludedAccountsList(listOfAccountsToExclude);
if (includeTransfers) {
return prismaTx.$queryRaw`SELECT sum(if(type = 'I' OR
(type = 'T' AND accounts_account_to_id NOT IN (${accountsToExcludeListInSQL})),
amount,
0)) as 'category_balance_credit',

const sqlQuery = includeTransfers ?
prismaTx.$queryRaw`SELECT sum(if(type = 'I', amount, 0)) as 'category_balance_credit',
sum(if(type = 'E' OR
(type = 'T' AND accounts_account_from_id NOT IN (${accountsToExcludeListInSQL})),
(type = 'T' AND accounts_account_to_id IN (${Prisma.join(listOfAccountsToExclude.map((a) => a.account_id))})),
amount,
0)) as 'category_balance_debit'
FROM transactions
WHERE date_timestamp between ${fromDate} AND ${toDate}
AND categories_category_id = ${categoryId} `;
}
return prismaTx.$queryRaw`SELECT sum(if(type = 'I', amount, 0)) as 'category_balance_credit',
AND categories_category_id = ${categoryId} ` :
prismaTx.$queryRaw`SELECT sum(if(type = 'I', amount, 0)) as 'category_balance_credit',
sum(if(type = 'E', amount, 0)) as 'category_balance_debit'
FROM transactions
WHERE date_timestamp between ${fromDate} AND ${toDate}
AND categories_category_id = ${categoryId} `;

return sqlQuery;
}, dbClient);

export interface CalculatedCategoryAmounts {
Expand Down

0 comments on commit ae27265

Please sign in to comment.