Skip to content

Feature/auth wallet money apis - #4

Merged
shihab3point14 merged 6 commits into
mainfrom
feature/auth-wallet-money-apis
Aug 16, 2026
Merged

Feature/auth wallet money apis#4
shihab3point14 merged 6 commits into
mainfrom
feature/auth-wallet-money-apis

Conversation

@shihab3point14

Copy link
Copy Markdown
Member

No description provided.

Copilot AI lite review requested due to automatic review settings August 16, 2026 06:42
@shihab3point14
shihab3point14 merged commit b151c60 into main Aug 16, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new Node/Express API surface for payNEXT covering auth, wallets, and money movement (top-up, withdraw, transfer), plus basic DB wiring and containerization.

Changes:

  • Added JWT-based auth endpoints (/auth/*) and requireAuth middleware.
  • Added wallet endpoints (/wallets/*) and money movement endpoints (/wallets/:id/top-up, /wallets/:id/withdraw, /transfers).
  • Added Postgres connection setup, error handling, and Docker packaging.

Reviewed changes

Copilot reviewed 19 out of 21 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
api/src/services/moneyService.js Adds DB transaction helpers (BEGIN/COMMIT/ROLLBACK), wallet row locking, balance updates, and transaction/gateway logging utilities.
api/src/server.js Adds API entrypoint to start the Express app.
api/src/routes/walletRoutes.js Defines authenticated wallet routes plus top-up/withdraw endpoints.
api/src/routes/requestRoutes.js Currently empty but mounted by the master router (this breaks startup).
api/src/routes/moneyRoutes.js Defines authenticated transfer (“sendMoney”) route.
api/src/routes/index.js Adds master router with /health and mounts auth/wallet/transfer/payment-request route groups.
api/src/routes/authRoutes.js Defines register/login/me auth routes.
api/src/models/walletModel.js Adds wallet persistence (create/list/find).
api/src/models/userModel.js Adds user persistence (create/findByEmail/findById).
api/src/middleware/errorHandler.js Adds centralized error handler returning safe 500 responses.
api/src/middleware/auth.js Adds JWT signing and auth enforcement middleware.
api/src/controllers/walletController.js Adds wallet controller endpoints including transactions listing (currently depends on missing model).
api/src/controllers/moneyController.js Implements top-up, withdraw, and transfer logic using DB transactions and row locks.
api/src/controllers/authController.js Implements registration/login/me flows, including initial wallet creation.
api/src/config/db.js Adds Postgres Pool configuration (currently mismatched with .env.example fields).
api/src/app.js Wires Express app, JSON parsing, versioned routes, 404 handler, and error handler.
api/package.json Adds API package metadata and runtime dependencies/scripts.
api/package-lock.json Locks dependency tree for reproducible installs.
api/Dockerfile Adds Docker build/run definition for the API service.
api/.env.example Adds environment variable template (currently has incorrect DB port example).
api/.dockerignore Prevents copying node_modules and .env into Docker build context.
Files not reviewed (1)
  • api/package-lock.json: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1 to +2
const walletModel = require("../models/walletModel");
const transactionModel = require("../models/transactionModel");
Comment thread api/src/routes/index.js
Comment on lines +21 to +22
router.use("/transfers", moneyRoutes);
router.use("/payment-requests", requestRoutes);
Comment on lines +103 to +121
const data = await withTransaction(async (client) => {
const from = await lockWallet(client, fromWalletId);
if (!from) throw new ApiError("Sender wallet not found", 404);
if (from.user_id !== req.user.sub) throw new ApiError("Not your wallet", 403);

const toRes = await client.query(
"SELECT * FROM wallets WHERE wallet_number = $1",
[toWalletNumber]
);
const to = toRes.rows[0];
if (!to) throw new ApiError("Receiver wallet not found", 404);
if (to.id === from.id) throw new ApiError("Cannot send to the same wallet", 400);
if (from.status !== "active" || to.status !== "active")
throw new ApiError("Wallet is not active", 400);
if (from.currency !== to.currency) throw new ApiError("Currency mismatch", 400);
if (Number(from.balance) < amount) throw new ApiError("Insufficient balance", 400);

const lockedTo = await lockWallet(client, to.id);

Comment on lines +1 to +22
const jwt = require("jsonwebtoken");

function signToken(user) {
return jwt.sign({ sub: user.id, email: user.email }, process.env.JWT_SECRET, {
expiresIn: "7d",
});
}

function requireAuth(req, res, next) {
const header = req.headers.authorization || "";
const token = header.startsWith("Bearer ") ? header.slice(7) : null;
if (!token)
return res.status(401).json({ success: false, error: "Missing token" });
try {
req.user = jwt.verify(token, process.env.JWT_SECRET);
next();
} catch {
return res
.status(401)
.json({ success: false, error: "Invalid or expired token" });
}
}
Comment thread api/src/config/db.js
Comment on lines +4 to +10
const pool = new Pool({
host: process.env.DB_HOST || "localhost",
port: Number(process.env.DB_PORT || 5432),
user: process.env.DB_USER || "paynext",
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME || "paynext_db",
});
Comment thread api/.env.example
Comment on lines +11 to +15
DB_HOST=your-db-host.supabase.com
DB_PORT=3000
DB_USER=postgres
DB_PASSWORD=change_me
DB_NAME=postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants