Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor monorepo #1

Closed
wants to merge 107 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
ae87627
Initial commit
aacmal Jan 8, 2023
0dec25e
Initialize project
aacmal Jan 8, 2023
5ca0f52
Update README.md
aacmal Jan 8, 2023
5163573
added dbconfig.ts for database connection
aacmal Jan 8, 2023
ab3164b
fix error when adding new transaction
aacmal Jan 8, 2023
cdee5b7
added endpoint to add new transaction
aacmal Jan 8, 2023
47f9faa
configure tsconfig.json
aacmal Jan 9, 2023
f8967d3
added endpoints for transaction
aacmal Jan 9, 2023
f85240c
refactor controller and create services
aacmal Jan 14, 2023
9d3369b
fix type error and rename route file name
aacmal Jan 15, 2023
8115729
added authentication
aacmal Jan 15, 2023
7dff51b
only store user id on jwt payload
aacmal Jan 16, 2023
7d57f7b
refactor routes and authentication
aacmal Jan 16, 2023
e2347c0
added relation one to many (user to transaction)
aacmal Jan 16, 2023
cb79e85
removed passport local and implement access token and refresh token u…
aacmal Jan 17, 2023
29a30d4
added user-agent to refresh token
aacmal Jan 18, 2023
44d616a
added getTotalTransaction controller
aacmal Jan 18, 2023
ecd42e1
fix configuration
aacmal Jan 21, 2023
da668e7
added some transaction service
aacmal Jan 23, 2023
f0f9a9a
added vercel configuration
aacmal Jan 23, 2023
9419c56
disable database connection for testing purpose
aacmal Jan 23, 2023
453aa73
push output folder
aacmal Jan 23, 2023
49beb57
fix error jwt
aacmal Jan 23, 2023
b5599ba
remove promise to run application
aacmal Jan 24, 2023
1d602bd
add database string url into .env
aacmal Jan 24, 2023
9989ccf
fix vercel error
aacmal Jan 24, 2023
0789b67
remove on aggregate and configure cors option
aacmal Jan 25, 2023
d71072c
change routes to fetch all transactions
aacmal Jan 26, 2023
b5a515a
added Wallet Schema, service, controller, and route
aacmal Jan 27, 2023
369cf41
added wallet route
aacmal Jan 27, 2023
4db9830
added wallet service to update transaction
aacmal Jan 28, 2023
5811593
fix logic error when removing transaction
aacmal Jan 28, 2023
3212ab5
Merge branch 'main' into wallet
aacmal Jan 28, 2023
54f8dd1
abort calculate manual wallet balance
aacmal Jan 29, 2023
8a35ed0
fix logic error
aacmal Jan 29, 2023
e1fbd76
improve wallet service
aacmal Feb 1, 2023
00765fc
added initial balance of wallet if available
aacmal Feb 5, 2023
d660537
added color field
aacmal Feb 7, 2023
ea0073d
added total balance services
aacmal Feb 9, 2023
a2cbf40
added some route and wallet controller
aacmal Feb 9, 2023
b35390c
added wallet interface
aacmal Feb 10, 2023
cf2f630
Stopped tracking .env File and added .env.example
aacmal Feb 11, 2023
1d3e415
improve wallet service
aacmal Feb 11, 2023
1e04800
remove verb at transaction route
aacmal Feb 11, 2023
3048d4d
added transfer balance feature
aacmal Feb 11, 2023
0c210a4
fix response data
aacmal Feb 12, 2023
ede8387
fix error when integrating with frontend
aacmal Feb 16, 2023
230bad9
include balance activity in getOneWallet controller
aacmal Feb 16, 2023
a466718
fix balance history error
aacmal Feb 17, 2023
08e1cb2
fix path route for transfer wallet balance
aacmal Feb 20, 2023
4ba4e82
added wallet transactions route
aacmal Feb 21, 2023
16ff04d
fix route for update transaction
aacmal Feb 24, 2023
17d28f9
add walletId to getTransactionByDate
aacmal Feb 25, 2023
e4d61f0
added deletedTransaction data to deleteTransaction response
aacmal Feb 27, 2023
6968eab
added logged devices
aacmal Mar 1, 2023
86c9e56
added bot service
aacmal Mar 2, 2023
91bd9e6
added route to detach telegram
aacmal Mar 3, 2023
54b711a
added wallet balance history endpoint
aacmal Mar 5, 2023
b388e68
added scripts to generate dummy data
aacmal Mar 12, 2023
b37ab05
fix error at Transaction service
aacmal Mar 13, 2023
d9aeeba
added Wallet name to transfer balance between wallet
aacmal Apr 8, 2023
1679daa
disable balance hisotory
aacmal Apr 8, 2023
d76521e
fix sorting total transaction by date
aacmal Apr 8, 2023
0d05dc8
add reset password route
aacmal May 24, 2023
195c210
refactor validator
aacmal May 25, 2023
9a84d59
update env example
aacmal May 25, 2023
29eaa64
add option description transfer balance
aacmal May 25, 2023
e7b4107
add transaction pagination
aacmal May 29, 2023
7be3ef1
fix infinite transaction response
aacmal May 30, 2023
233addc
build tsc
aacmal May 30, 2023
45d3215
fix: cors config
aacmal Jul 2, 2023
3e52987
fix cors error
aacmal Jul 8, 2023
09cf59d
fix typo response
aacmal Jul 8, 2023
c5613d4
add samesite to cors header
aacmal Jul 8, 2023
53a4b4b
add samesite to set cookie response
aacmal Jul 8, 2023
12a722b
feat: reordering wallet
aacmal Jul 31, 2023
5ab17cb
update cors origin
aacmal Aug 1, 2023
482bce3
fix: ordering wallet
aacmal Aug 1, 2023
c1a089c
add wizard bot transaction
aacmal Aug 3, 2023
83bd10f
finishing created transaction with bot wizard scene
aacmal Aug 4, 2023
da27b5b
fix error when adding new transaction
aacmal Aug 4, 2023
291b255
fix bug and remove unused code
aacmal Aug 4, 2023
0b7db64
add "tambah lagi" inline button
aacmal Aug 5, 2023
aef5076
added transaction by month
aacmal Aug 19, 2023
5d090c1
change expires access token to 5m
aacmal Aug 19, 2023
aec70a3
select updatedAt on wallet res
aacmal Aug 29, 2023
81d2057
feat: search transactions by description
aacmal Sep 4, 2023
37f3d39
fix: search case-insesitive
aacmal Sep 4, 2023
b1e2c17
feat: added wallet mode isCredit
aacmal Oct 22, 2023
44e9fe2
fix response
aacmal Oct 22, 2023
77360a4
added loginWithGoogle
aacmal Nov 2, 2023
85a7858
Merge remote-tracking branch 'refs/remotes/origin/main'
aacmal Nov 2, 2023
19d6add
Fix password validation and add user registration
aacmal Nov 5, 2023
f6e665e
added Type to cors.config.ts
aacmal Nov 5, 2023
948fcdf
Update wallet service functions to use userId and
aacmal Nov 5, 2023
c1ba952
added getTotalTransactionByPeriods interval
aacmal Nov 7, 2023
c42c344
update .env.example
aacmal Nov 8, 2023
fee97bd
monorepo - moving files
aacmal Mar 3, 2024
8a9e1a0
monorepo - moving backend files
aacmal Mar 3, 2024
205081d
Merge remote-tracking branch 'backend/main'
aacmal Mar 3, 2024
d8ab47f
Refactor monorepo
aacmal Mar 3, 2024
6a02569
Fix eslint and prettier configuration
aacmal Mar 3, 2024
3cfe573
Fix css module error on frontend
aacmal Mar 4, 2024
a3b01e9
Refactor backend repository
aacmal Mar 5, 2024
0bda0ec
Fix eslint-config
aacmal Mar 5, 2024
7029de3
Fix eslint error
aacmal Mar 5, 2024
2b41d98
Reformat frontend code using prettier
aacmal Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 0 additions & 13 deletions .eslintrc.json

This file was deleted.

56 changes: 3 additions & 53 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,55 +1,5 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# vscode
.vscode

# env
.env.local
.env
node_modules

# PWA
**/public/precache.*.*.js
**/public/sw.js
**/public/workbox-*.js
**/public/worker-*.js
**/public/fallback-*.js
**/public/precache.*.*.js.map
**/public/sw.js.map
**/public/workbox-*.js.map
**/public/worker-*.js.map
**/public/fallback-*.js
# turbo
.turbo
5 changes: 0 additions & 5 deletions .idea/.gitignore

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/finaki-frontend.iml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

24 changes: 24 additions & 0 deletions apps/backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Runningtime
PORT=3001

# Database
MONGO_URL="mongodb:https://127.0.0.1:27017/database_name"
TELEGRAM_BOT_TOKEN="5745052045:AAHfR2_VnFXI_o5CUZoZTcv5jRvwx40QjQ8"

# JWT
ACCESS_TOKEN_SECRET_KEY="SECRET_EXAMPLE_ACCESS"
REFRESH_TOKEN_SECRET_KEY="SECRET_EXAMPLE_REFRESH"
RESET_PASSWORD_TOKEN_SECRET_KEY="SECRET_EXAMPLE_RESET_PASSWORD"

# Email
EMAIL_HOST="smtp.gmail.com"
EMAIL_PORT=587
[email protected]
EMAIL_PASSWORD=zwsszkhaeojxorhb

# URL
FRONTEND_URL="https://localhost:3000"

# Google OAuth
CLIENT_ID="CLIENT_ID"
CLIENT_SECRET="XXXIIIPPP"
10 changes: 10 additions & 0 deletions apps/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# IDE configuration
/.vscode

# Dependency
/node_modules

# Build

# environment
.env
2 changes: 2 additions & 0 deletions apps/backend/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
7 changes: 7 additions & 0 deletions apps/backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Definition

# Issues
During refactoring to Monorepo, I found this file is so many eslint error
I Don't know why, but I think this is because of the typescript version
or maybe the eslint version, so for now I will disable some eslint rule
and I will fix it later
47 changes: 47 additions & 0 deletions apps/backend/dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable no-console */
import cookieParse from "cookie-parser";
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
import passport from "passport";
import { corsConfig } from "./src/configs/cors.config";
import database from "./src/configs/database.config";
import AppRoutes from "./src/routes/index.route";
import bot from "./src/services/bot.service";
dotenv.config();
export const ACCESS_TOKEN_SECRET = process.env.ACCESS_TOKEN_SECRET_KEY;
export const REFRESH_TOKEN_SECRET = process.env.REFRESH_TOKEN_SECRET_KEY;
const app = express();
const port = process.env.PORT ?? 3000;
app.get("/", (req, res) => {
res.json({
message: "Hello World!",
});
res.statusCode = 200;
});
app.use(cors(corsConfig));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParse());
app.use(passport.initialize());
require("./src/middlewares/passport");
// Logging request
app.use((req, res, next) => {
console.log(`[${req.method}] ${req.path} - ${req.get("user-agent")}`);
next();
});
app.use("/api", AppRoutes);
database().catch((error) => {
console.log(error);
});
app.listen(port, () => {
bot
.launch()
.then(() => {
console.log("Bot is running");
})
.catch((error) => {
console.log(error);
});
console.log(`Server is running at https://localhost:${port}`);
});
32 changes: 32 additions & 0 deletions apps/backend/dist/scripts/database/deleteTransactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import database from "../../src/configs/database.config";
import TransactionModel from "../../src/models/transaction.model";
import UserModel from "../../src/models/user.model";
import WalletModel from "../../src/models/wallet.model";
const userId = "640c5fe8e4607df44520b092";
const walletId = "640c9a0c97321cead51393ca";
async function deleteTransactions() {
await database();
await TransactionModel.deleteMany({
userId: userId,
}).then(() => {
// eslint-disable-next-line no-console
console.log("Transactions deleted successfully");
});
await UserModel.updateOne({
_id: userId,
}, {
$set: {
transactions: [],
},
});
await WalletModel.updateOne({
_id: walletId,
}, {
$set: {
transactions: [],
balance: 0,
},
});
process.exit(0);
}
await deleteTransactions();
98 changes: 98 additions & 0 deletions apps/backend/dist/scripts/database/generateTransactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* eslint-disable no-console */
import { faker } from "@faker-js/faker";
import mongoose from "mongoose";
import database from "../../src/configs/database.config";
import TransactionModel from "../../src/models/transaction.model";
import UserModel from "../../src/models/user.model";
import WalletModel from "../../src/models/wallet.model";
import { updateBalance } from "../../src/services/wallet.service";
const userId = "6451ae1759bfa320f0728f7e";
const walletId = null;
const transactionType = "in";
const seeds = {
dataPerDay: 7, // random number between 1 and 7 transactions per day
length: 7, // number of days to generate transaction data for 7 days
};
async function generateTransactions() {
console.clear();
await database();
faker.setLocale("id_ID");
const startDate = new Date();
startDate.setDate(startDate.getDate() - seeds.length);
const transactions = [];
const transactionIds = [];
for (let i = 1; i <= seeds.length; i++) {
const date = new Date();
date.setDate(startDate.getDate() + i);
const dataPerDay = Math.floor(Math.random() * seeds.dataPerDay) + 1;
for (let j = 0; j < dataPerDay; j++) {
const transaction = {
_id: new mongoose.Types.ObjectId(),
userId,
walletId: walletId,
description: faker.finance.transactionDescription(),
amount: Math.floor(Math.random() * 7000) + 1,
type: transactionType,
createdAt: date,
updatedAt: date,
};
transactions.push(transaction);
transactionIds.push(transaction._id);
}
}
const totalBalance = transactions.reduce((acc, curr) => {
return acc + curr.amount;
}, 0);
console.log("Total balance changes: ", totalBalance);
if (!walletId) {
await TransactionModel.insertMany(transactions).then(() => {
console.log("Transactions generated successfully");
});
await UserModel.updateOne({
_id: userId,
}, {
$push: {
transactions: {
$each: transactionIds,
},
},
});
process.exit(0);
}
const wallet = await WalletModel.findById(walletId);
if (!wallet) {
console.log("Wallet not found");
process.exit(0);
}
if (transactionType === "out") {
if (wallet.balance < totalBalance) {
console.log("Balance is not enough");
console.error("Cancelled");
process.exit(0);
}
}
await TransactionModel.insertMany(transactions).then(() => {
console.log("Transactions generated successfully");
});
await UserModel.updateOne({
_id: userId,
}, {
$push: {
transactions: {
$each: transactionIds,
},
},
});
await WalletModel.updateOne({
_id: walletId,
}, {
$push: {
transactions: {
$each: transactionIds,
},
},
});
await updateBalance(walletId);
process.exit(0);
}
await generateTransactions();
8 changes: 8 additions & 0 deletions apps/backend/dist/src/configs/cors.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const corsConfig = {
origin: [
"https://finaki.vercel.app", // vercel domain
"https://finaki.acml.me", // production
"https://localhost:3000", // development
],
credentials: true,
};
13 changes: 13 additions & 0 deletions apps/backend/dist/src/configs/database.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable no-console */
import mongoose from "mongoose";
mongoose.set("strictQuery", false);
const database = async () => mongoose
.connect(process.env.MONGO_URL ?? "mongodb:https://127.0.0.1:27017/money-tracker")
.then(() => {
console.log("Database connected");
})
.catch((error) => {
console.log(error);
throw new Error("Error connecting to database");
});
export default database;
Loading