Skip to content

refactor: convert to TypeScript, update dependencies, fix bugs & improve code quality#1

Open
Marbot-claw wants to merge 2 commits into
ivanarifin:mainfrom
Marbot-claw:bot/refactor-convert-to-typescript-update-de-mnuqsfha
Open

refactor: convert to TypeScript, update dependencies, fix bugs & improve code quality#1
Marbot-claw wants to merge 2 commits into
ivanarifin:mainfrom
Marbot-claw:bot/refactor-convert-to-typescript-update-de-mnuqsfha

Conversation

@Marbot-claw

Copy link
Copy Markdown

Summary

Full refactor of the server codebase: migrated to TypeScript, updated all outdated dependencies, fixed critical bugs, and improved overall code quality & best practices.

Changes

🔷 TypeScript Migration

  • Converted all .js files to .ts
  • Added tsconfig.json with strict mode
  • Added proper type definitions for Request, Response, models, and controllers
  • Added @types/* packages for all dependencies

📦 Dependency Updates

Production:

Package Before After
jsonwebtoken 8.5.1 (CVE!) 9.0.2
sharp 0.31.2 0.33.5
cloudinary 1.32.0 2.5.1
axios 1.1.3 1.7.9
express 4.18.2 4.21.2
sequelize 6.25.5 6.37.5
bcryptjs 2.4.3 2.4.3 (latest)
cors 2.8.5 2.8.5 (latest)
dotenv 16.0.3 16.4.7
multer 1.4.5-lts.1 1.4.5-lts.1
nodemailer 6.8.0 6.10.0
pg 8.8.0 8.13.1
google-auth-library 8.6.0 9.15.0

Dev:

  • Added typescript, ts-node, @types/*, nodemon

🐛 Bug Fixes

  1. createTokensignToken in Google login controller (was causing ReferenceError)
  2. Duplicate origin in CORS config — removed conflicting property
  3. Hardcoded URL bopflix.herokuapp.com → replaced with process.env.BASE_URL
  4. Search redirect → now returns proper JSON error instead of res.redirect("/")
  5. Array mutation in spliceIntoChunks — replaced with non-mutating slice

🧹 Code Quality Improvements

  • Async bcrypt — replaced hashSync/compareSync with hash/compare (non-blocking)
  • Removed body-parser — Express 4.16+ has built-in express.json() and express.urlencoded()
  • Proper type safety — interfaces for User, Rent, Request extensions, error types
  • Cleaner middleware flow — proper error handler placement
  • Environment variable validation — added runtime checks
  • Better error messages — consistent error format across all endpoints

📁 File Structure (unchanged, just .ts extension)

src/
├── app.ts
├── config/config.json
├── controllers/
│   ├── rent.ts
│   ├── show.ts
│   └── user.ts
├── helpers/
│   ├── bcrypt.ts
│   └── jwt.ts
├── middlewares/
│   ├── authentication.ts
│   ├── authorize.ts
│   └── errorHandler.ts
├── models/
│   ├── index.ts
│   ├── rent.ts
│   └── user.ts
├── routes/
│   ├── index.ts
│   ├── rent.ts
│   ├── show.ts
│   └── user.ts
└── types/
    └── index.ts

Breaking Changes

  • Entry point changed: node app.jsnode dist/app.js (after tsc) or ts-node app.ts for dev
  • Need to run npm run build before deployment
  • BASE_URL env var now required (was hardcoded before)

How to Test

# Install dependencies
npm install

# Development
npm run dev

# Build TypeScript
npm run build

# Production
npm start

# Database setup
npm run db:dev

Test the endpoints:

# Register
curl -X POST http://localhost:3000/users/register \
  -H "Content-Type: application/json" \
  -d '{"username":"test","email":"test@test.com","password":"test123","phoneNumber":"08123","address":"Jakarta"}'

# Login
curl -X POST http://localhost:3000/users/login \
  -H "Content-Type: application/json" \
  -d '{"email":"test@test.com","password":"test123"}'

# Get shows
curl http://localhost:3000/

# Search shows
curl "http://localhost:3000/search?q=breaking"

…pdates, bug fixes

Major changes:
- Convert entire codebase from JavaScript to TypeScript
- Update all dependencies to latest stable versions
- Fix critical bugs (createToken→signToken, duplicate CORS origin, hardcoded URLs)
- Replace sync bcrypt with async version
- Remove redundant body-parser (Express has built-in)
- Add proper TypeScript interfaces and types
- Improve error handling and input validation
- Fix search endpoint (return JSON instead of redirect)
- Add nodemon to devDependencies
- Clean up middleware ordering and structure
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.

1 participant