Group income by any field and calculate sum & counts with date-range filter
✅
6.
Group income by date with date-range filter so that the data returned also includes dates with $0 income for data-visualisation
✅
7.
Group expenses by any field and calculate sum & counts with date-range filter
✅
8.
Group expenses by date with date-range filter so that the data returned also includes dates with $0 expenses for data-visualisation
✅
9.
Query average daily income with date-range filter
✅
10.
Query average daily expenses with date-range filter
✅
11.
Query total income with date-range filter
✅
12.
Query total expenses with date-range filter
✅
13.
Query net income with date-range filter
✅
14.
Prevent authenticated BUT unauthorised users from accessing ALL endpoints
✅
14.
Automatically add new users into a User table in DB after they signed up the app using Auth0
15.
Link up Income and Expense tables with User by introducing association rules
16.
Mutation for creating row for Income
17.
Mutation for updating row for Income
18.
Mutation for creating row for Expense
19.
Mutation for updating row for Expense
20.
Subscription with pagination for retrieving rows from Income
21.
Subscription with pagination for retrieving rows from Expense
⁉️ Challenges & workarounds
No.
Problem
Solution
1
Rate limit from Notion API + Ugly & Inconsistent response structure from Notion SDK
Migrate table to real DB (PostgreSQL)
2
DB data isn't in sync with data from Notion
Need Notion webhook to setup triggers but none available, current plan is to manually update DB from time to time
3
There are no out-of-box auth solutions for Nest + GraphQL + Auth0 in RBAC (Role-based access-control)
Implemented a custom guard that transforms request context from REST into GraphQL context then authenticate and authorise access based on the permissions field of the decoded jwt token payload.
4
When returning sum from IncomeGroupBy queries, the sum amount does not reflect the differences in currency (NZD and USD)
Need to either setup compulsory currency filter in query layer or auto-calculate all USD amount to NZD by real-time exchange rate on return
5
Need to show dates with $0 income for aggregated income queries by dynamic date-range filter for time-series chart display
Used dates API to populate empty dates
🛫 Running the app
# Installation
$ yarn
# build
$ yarn build
# development
$ yarn start
# watch mode
$ yarn dev
# production mode
$ yarn start:prod
## Test# unit tests
$ yarn test# unit tests - auto-update
$ yarn test:watch
# e2e tests
$ yarn test:e2e
# test coverage
$ yarn test:cov
## Database# database seeding
$ npx prisma db seed
# See DB using prisma studio
$ npx prisma studio
🔭 Sample query & response:
All queries are protected by guards, meaning only authorised users are able to execute the queries (which is me, myself and I)
Query income by payment method and calculate sum of income by payment method
# Note: endDate and dateStartInc are optional.# When date filters are not provided, the query will return all records`query {
incomeGroupBy (
field: "paymentMethod",
valueType: "sum"endDate: "Sun Nov 21 2021 12:12:28 GMT+1300 (New Zealand Daylight Time)"startDate: "Wed Sep 01 2021 12:12:28 GMT+1200 (New Zealand Standard Time)"
) {
incomePaymentMethodsum
}
}