Skip to content

7.22 Migrate QuoteModel to TypeScript#315

Merged
Om7035 merged 2 commits intoQuoteVote:mainfrom
shubham-01-star:7.22-migrate-quote-model-ts
Apr 24, 2026
Merged

7.22 Migrate QuoteModel to TypeScript#315
Om7035 merged 2 commits intoQuoteVote:mainfrom
shubham-01-star:7.22-migrate-quote-model-ts

Conversation

@shubham-01-star
Copy link
Copy Markdown
Collaborator

Summary

Migrates the QuoteModel from JavaScript to TypeScript with full Mongoose 8.x typing. Adds a new Quote.ts model using existing QuoteDocument and QuoteModel interfaces from app/types/mongoose.ts, and includes unit tests for schema validation and static methods.

Changes

New Files

  • app/data/models/Quote.ts — Typed Mongoose model with:
    • Schema fields: userId, postId, quote, startWordIndex, endWordIndex, created
    • Text index on quote field
    • Static methods: findByPostId, findLatest
  • __tests__/unit/models/Quote.test.ts — Unit tests covering:
    • Required field validation (userId, postId, quote)
    • Default values (created)
    • Optional fields (startWordIndex, endWordIndex)
    • Static method behavior (findByPostId, findLatest)

Modified Files

  • app/data/models/index.ts — Added Quote barrel export

Verification

  • All 5 unit tests pass
  • npx tsc --noEmit — clean (exit 0)
  • pnpm build — success (exit 0)

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 21, 2026

@shubham-01-star is attempting to deploy a commit to the Louis Girifalco's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
quotevote Ready Ready Preview, Comment Mar 21, 2026 7:31pm

@Om7035 Om7035 self-requested a review April 4, 2026 12:17
Copy link
Copy Markdown
Collaborator

@Om7035 Om7035 left a comment

Choose a reason for hiding this comment

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

🚨 PR Review — Request Changes ❌

🔴 Critical Issues

1. PR scope is far too broad for the title

  • PR claims “Migrate QuoteModel to TypeScript”, but includes:
    • 14 commits
    • Multiple models/tests
    • Stripe + type-related changes
  • ❗ High merge risk and difficult to review safely

2. Quote statics are weakly validated

  • findByPostId(postId: string) directly queries { postId }
  • ❌ No ObjectId validation/casting
  • ⚠️ Can lead to:
    • Inconsistent behavior
    • Hidden malformed input bugs

3. Missing schema constraints for quote range integrity

  • startWordIndex / endWordIndex are optional but:
    • ❌ No non-negative validation
    • ❌ No startWordIndex <= endWordIndex check
    • ❌ No enforcement of pair presence

➡️ Risk: corrupt quote spans


4. Tests are shallow (mock-based, not real DB validation)

  • Current tests:
    • Mock find().sort().limit()
  • ❌ Do NOT validate:
    • MongoDB behavior
    • Indexes
    • ObjectId coercion

5. CI is currently failing

  • ❌ 1 error + warnings
  • Includes:
    • Missing hook dependency (dataKey)
    • Lint issues
  • 🚫 Blocks production-safe merge

🛠 Inline Suggestions

📁 quotevote-backend/app/data/models/Quote.ts

  • Add ObjectId validation in findByPostId
  • Add index range validation
  • Normalize quote (trim + bounds)
  • Add index:
{ postId: 1, created: 1 }

@Om7035
Copy link
Copy Markdown
Collaborator

Om7035 commented Apr 4, 2026

@shubham-01-star can you connect with me on discord I have sent a message to you

@Om7035 Om7035 self-requested a review April 23, 2026 18:05
Copy link
Copy Markdown
Collaborator

@Om7035 Om7035 left a comment

Choose a reason for hiding this comment

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

@shubham-01-star

Primary blockers

--

  1. PR scope does not match title (“Migrate QuoteModel to TypeScript”).
  • PR contains 14 commits and includes earlier migrations (simple models, User, Post, Comment, Stripe typing updates), not only Quote.
  • This makes review and rollback high-risk.
  • Recommendation: split to a Quote-only PR (or explicitly retitle/reframe as aggregate migration PR).
     
  1. Quote static method input validation gap (findByPostId(postId: string)).
  • Current approach directly queries by string input without explicit ObjectId validation/casting.
  • Risk: malformed input behavior becomes inconsistent across call paths.
  • Recommendation: validate/cast at static boundary and define deterministic failure behavior.
     
  1. Missing Quote span integrity constraints.
  • startWordIndex / endWordIndex are optional but there is no visible guard for:
  • non-negative values,
  • startWordIndex <= endWordIndex,
  • pair consistency (if one is set, the other must be set).
  • Recommendation: add schema validators or service-level invariant checks.
     
  1. Tests are mostly mocked and do not prove database-level behavior.
  • Current tests emphasize mocked chains and unit behavior.
  • Missing integration checks for ObjectId casting, index behavior, and schema validator enforcement.
  • Recommendation: add integration tests using in-memory Mongo for Quote model invariants.
     
  1. CI signal not clean at review time.
  • Review thread cites failing checks and lint/hook issues.
  • Recommendation: block merge until all required checks pass on latest head commit.
     

Additional recommendation

  • If Quote model is merged independently, add or verify a practical read index for feed usage, e.g. { postId: 1, created: -1 }, based on real query plans.
     

Suggested merge gate for #315

  • Narrow PR scope to Quote-only (or retitle as aggregate migration and split follow-ups).
  • Add ObjectId validation/casting in Quote statics.
  • Add quote range integrity validators.
  • Add integration tests for schema + index behavior.
  • Ensure required CI checks are green on head.

@Om7035 Om7035 merged commit cc65889 into QuoteVote:main Apr 24, 2026
2 of 3 checks passed
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.

2 participants