Skip to content

Commit

Permalink
Merge branch 'main' into feat/investments
Browse files Browse the repository at this point in the history
  • Loading branch information
letehaha committed Jun 11, 2024
2 parents 1c257b6 + a968eb5 commit 173650a
Show file tree
Hide file tree
Showing 13 changed files with 452 additions and 487 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.9.0
21.7.3
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20.9.0
FROM node:21.7.3
WORKDIR /app
COPY . .
RUN npm ci
Expand Down
414 changes: 186 additions & 228 deletions package-lock.json

Large diffs are not rendered by default.

115 changes: 57 additions & 58 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"url": "git+https://github.com/letehaha/budget-tracker-be.git"
},
"volta": {
"node": "20.9.0"
"node": "21.7.3"
},
"author": "",
"license": "ISC",
Expand All @@ -52,65 +52,64 @@
},
"homepage": "https://github.com/letehaha/budget-tracker-be#readme",
"dependencies": {
"@polygon.io/client-js": "^7.3.2",
"axios": "^1.6.1",
"bcryptjs": "^2.4.3",
"config": "^3.3.9",
"connect-redis": "^5.0.0",
"cors": "^2.8.5",
"crypto-js": "^4.2.0",
"currency-codes": "^2.1.0",
"date-fns": "^2.30.0",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-validator": "^7.0.1",
"express-winston": "^4.2.0",
"jsonwebtoken": "^9.0.2",
"locale": "^0.1.0",
"lodash": "^4.17.21",
"morgan": "^1.10.0",
"@polygon.io/client-js": "7.3.2",
"axios": "1.6.8",
"bcryptjs": "2.4.3",
"config": "3.3.11",
"connect-redis": "5.0.0",
"cors": "2.8.5",
"crypto-js": "4.2.0",
"currency-codes": "2.1.0",
"date-fns": "3.6.0",
"dotenv": "16.4.5",
"express": "4.19.2",
"express-validator": "7.0.1",
"express-winston": "4.2.0",
"jsonwebtoken": "9.0.2",
"locale": "0.1.0",
"lodash": "4.17.21",
"morgan": "1.10.0",
"p-queue": "6.6.2",
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
"pg": "^8.11.3",
"pg-hstore": "^2.3.4",
"redis": "^3.1.1",
"reflect-metadata": "^0.1.13",
"sequelize": "^6.35.0",
"sequelize-cli": "^6.6.2",
"sequelize-typescript": "^2.1.6",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"uuid": "^9.0.1",
"winston": "^3.11.0"
"passport": "0.6.0",
"passport-jwt": "4.0.1",
"pg": "8.11.5",
"pg-hstore": "2.3.4",
"redis": "3.1.1",
"sequelize": "6.37.3",
"sequelize-cli": "6.6.2",
"sequelize-typescript": "2.1.6",
"ts-node": "10.9.2",
"typescript": "5.4.5",
"uuid": "9.0.1",
"winston": "3.13.0"
},
"devDependencies": {
"@faker-js/faker": "^8.2.0",
"@types/config": "^3.3.3",
"@types/cors": "^2.8.16",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.8",
"@types/locale": "^0.1.4",
"@types/lodash": "^4.14.202",
"@types/morgan": "^1.9.9",
"@types/node": "^20.9.0",
"@types/passport": "^1.0.15",
"@types/sequelize": "^4.28.20",
"@types/validator": "^13.11.6",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"cross-env": "^7.0.3",
"eslint": "^7.31.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.29.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"module-alias": "^2.2.3",
"nodemon": "^3.0.1",
"prettier": "^3.0.3",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"tslint": "^6.1.3"
"@faker-js/faker": "8.4.1",
"@types/config": "3.3.4",
"@types/cors": "2.8.17",
"@types/express": "4.17.21",
"@types/jest": "29.5.12",
"@types/locale": "0.1.4",
"@types/lodash": "4.17.5",
"@types/morgan": "1.9.9",
"@types/node": "20.12.7",
"@types/passport": "1.0.16",
"@types/sequelize": "4.28.20",
"@types/validator": "13.11.9",
"@typescript-eslint/eslint-plugin": "6.10.0",
"@typescript-eslint/parser": "6.10.0",
"cross-env": "7.0.3",
"eslint": "7.31.0",
"eslint-config-airbnb-base": "14.2.1",
"eslint-import-resolver-alias": "1.1.2",
"eslint-plugin-import": "2.29.1",
"husky": "8.0.3",
"jest": "29.7.0",
"module-alias": "2.2.3",
"nodemon": "3.1.0",
"prettier": "3.2.5",
"supertest": "6.3.4",
"ts-jest": "29.1.2",
"tslint": "6.1.3"
}
}
1 change: 0 additions & 1 deletion src/controllers/crypto/binance.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios from 'axios';
// const CryptoJS = require('crypto-js');
import crypto from 'crypto';

import { API_ERROR_CODES, API_RESPONSE_STATUS } from 'shared-types';
Expand Down
31 changes: 3 additions & 28 deletions src/services/stats/get-balance-history-for-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,7 @@ import { GenericSequelizeModelAttributes } from '@common/types';
import { connection } from '@models/index';
import * as Balances from '@models/Balances.model';
import * as Accounts from '@models/Accounts.model';

interface DateQuery {
// yyyy-mm-dd
from?: string;
// yyyy-mm-dd
to?: string;
}

const getWhereConditionForTime = ({ from, to }: DateQuery) => {
const where: { date?: Record<symbol, Date[] | Date> } = {};

if (from && to) {
where.date = {
[Op.between]: [new Date(from), new Date(to)],
};
} else if (from) {
where.date = {
[Op.gte]: new Date(from),
};
} else if (to) {
where.date = {
[Op.lte]: new Date(to),
};
}

return where;
};
import { getWhereConditionForTime } from './utils';

/**
* Retrieves the balances for the requested account for a user within a specified date range.
Expand Down Expand Up @@ -74,7 +48,7 @@ export const getBalanceHistoryForAccount = async (

const dataAttributes = ['date', 'amount'];
const balancesInRange = await Balances.default.findAll({
where: getWhereConditionForTime({ from, to }),
where: getWhereConditionForTime({ from, to, columnName: 'date' }),
order: [['date', 'ASC']],
include: [
{
Expand Down Expand Up @@ -146,6 +120,7 @@ export const getBalanceHistoryForAccount = async (

return data;
} catch (err) {
console.log(err);
if (!isTxPassedFromAbove) {
await transaction.rollback();
}
Expand Down
31 changes: 3 additions & 28 deletions src/services/stats/get-balance-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,7 @@ import { GenericSequelizeModelAttributes } from '@common/types';
import { connection } from '@models/index';
import * as Balances from '@models/Balances.model';
import * as Accounts from '@models/Accounts.model';

interface DateQuery {
// yyyy-mm-dd
from?: string;
// yyyy-mm-dd
to?: string;
}

const getWhereConditionForTime = ({ from, to }: DateQuery) => {
const where: { date?: Record<symbol, Date[] | Date> } = {};

if (from && to) {
where.date = {
[Op.between]: [new Date(from), new Date(to)],
};
} else if (from) {
where.date = {
[Op.gte]: new Date(from),
};
} else if (to) {
where.date = {
[Op.lte]: new Date(to),
};
}

return where;
};
import { getWhereConditionForTime } from './utils';

/**
* Retrieves the balances for all the accounts for a user within a specified date range.
Expand Down Expand Up @@ -72,7 +46,7 @@ export const getBalanceHistory = async (
const dataAttributes = ['date', 'amount', 'accountId'];
// Fetch all balance records within the specified date range for the user
const balancesInRange = await Balances.default.findAll({
where: getWhereConditionForTime({ from, to }),
where: getWhereConditionForTime({ from, to, columnName: 'date' }),
order: [['date', 'ASC']],
include: [
{
Expand Down Expand Up @@ -172,6 +146,7 @@ export const getBalanceHistory = async (

return data;
} catch (err) {
console.log(err);
if (!isTxPassedFromAbove) {
await transaction.rollback();
}
Expand Down
31 changes: 2 additions & 29 deletions src/services/stats/get-expenses-history.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Op } from 'sequelize';
import {
TransactionModel,
TRANSACTION_TYPES,
Expand All @@ -9,33 +8,7 @@ import { GenericSequelizeModelAttributes } from '@common/types';

import { connection } from '@models/index';
import * as Transactions from '@models/Transactions.model';

interface DateQuery {
// yyyy-mm-dd
from?: string;
// yyyy-mm-dd
to?: string;
}

const getWhereConditionForTime = ({ from, to }: DateQuery) => {
const where: { time?: Record<symbol, Date[] | Date> } = {};

if (from && to) {
where.time = {
[Op.between]: [new Date(from), new Date(to)],
};
} else if (from) {
where.time = {
[Op.gte]: new Date(from),
};
} else if (to) {
where.time = {
[Op.lte]: new Date(to),
};
}

return where;
};
import { getWhereConditionForTime } from './utils';

export type GetExpensesHistoryResponseSchema = Pick<
TransactionModel,
Expand Down Expand Up @@ -98,7 +71,7 @@ export const getExpensesHistory = async (
userId,
transferNature: TRANSACTION_TRANSFER_NATURE.not_transfer,
transactionType: TRANSACTION_TYPES.expense,
...getWhereConditionForTime({ from, to }),
...getWhereConditionForTime({ from, to, columnName: 'time' }),
}),
order: [['time', 'ASC']],
raw: attributes.raw || true,
Expand Down
Loading

0 comments on commit 173650a

Please sign in to comment.