Skip to content

Commit

Permalink
feat: Allow exclude transfer txs from GET /transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
letehaha committed Jan 21, 2024
1 parent b028fb0 commit 1378f24
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
1 change: 1 addition & 0 deletions shared-types/routes/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface GetTransactionsQuery extends QueryPayload {
type?: TRANSACTION_TYPES;
accountType?: ACCOUNT_TYPES;
accountId?: number;
excludeTransfer?: boolean;
}

export type GetTransactionsResponse = TransactionModel[];
Expand Down
18 changes: 12 additions & 6 deletions src/controllers/transactions.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { API_RESPONSE_STATUS, SORT_DIRECTIONS } from 'shared-types';
import {
API_RESPONSE_STATUS,
SORT_DIRECTIONS,
endpointsTypes,
} from 'shared-types';
import { CustomResponse } from '@common/types';
import { ValidationError } from '@js/errors';
import * as transactionsService from '@services/transactions';
Expand All @@ -8,7 +12,7 @@ export const getTransactions = async (req, res: CustomResponse) => {
try {
const { id: userId } = req.user;
const {
sortDirection = SORT_DIRECTIONS.desc,
sort = SORT_DIRECTIONS.desc,
limit,
from = 0,
type: transactionType,
Expand All @@ -19,13 +23,14 @@ export const getTransactions = async (req, res: CustomResponse) => {
includeCategory,
includeAll,
nestedInclude,
isRaw,
} = req.query;
// isRaw,
excludeTransfer,
}: endpointsTypes.GetTransactionsQuery = req.query;

const data = await transactionsService.getTransactions({
userId,
transactionType,
sortDirection,
sortDirection: sort,
limit,
from,
accountType,
Expand All @@ -35,7 +40,8 @@ export const getTransactions = async (req, res: CustomResponse) => {
includeCategory,
includeAll,
nestedInclude,
isRaw,
excludeTransfer,
isRaw: false,
});

return res.status(200).json({
Expand Down
11 changes: 10 additions & 1 deletion src/models/Transactions.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ export const getTransactions = async (
includeAll,
nestedInclude,
isRaw = false,
excludeTransfer,
}: {
from: number;
limit: number;
Expand All @@ -393,6 +394,7 @@ export const getTransactions = async (
includeAll: boolean;
nestedInclude: boolean;
isRaw: boolean;
excludeTransfer?: boolean;
},
{ transaction }: { transaction?: Transaction } = {},
) => {
Expand All @@ -408,7 +410,14 @@ export const getTransactions = async (
include,
where: {
userId,
...removeUndefinedKeys({ accountType, accountId, transactionType }),
...removeUndefinedKeys({
accountType,
accountId,
transactionType,
transferNature: excludeTransfer
? TRANSACTION_TRANSFER_NATURE.not_transfer
: undefined,
}),
},
transaction,
offset: from,
Expand Down
35 changes: 20 additions & 15 deletions src/models/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { ACCOUNT_TYPES, SORT_DIRECTIONS, TRANSACTION_TYPES } from 'shared-types';
import {
ACCOUNT_TYPES,
SORT_DIRECTIONS,
TRANSACTION_TYPES,
} from 'shared-types';

export interface GetTransactionsParams {
userId: number,
sortDirection: SORT_DIRECTIONS,
includeUser: boolean,
includeAccount: boolean,
includeCategory: boolean,
includeAll: boolean,
nestedInclude: boolean,
transactionType: TRANSACTION_TYPES,
limit: number,
from: number,
accountType: ACCOUNT_TYPES,
accountId: number,
isRaw: boolean
}
userId: number;
sortDirection: SORT_DIRECTIONS;
includeUser: boolean;
includeAccount: boolean;
includeCategory: boolean;
includeAll: boolean;
nestedInclude: boolean;
transactionType: TRANSACTION_TYPES;
limit: number;
from: number;
accountType: ACCOUNT_TYPES;
accountId: number;
isRaw: boolean;
excludeTransfer?: boolean;
}

0 comments on commit 1378f24

Please sign in to comment.