Skip to content

7.22 Migrate QuoteModel to TypeScript#315

Open
shubham-01-star wants to merge 14 commits intoQuoteVote:mainfrom
shubham-01-star:7.22-migrate-quote-model-ts
Open

7.22 Migrate QuoteModel to TypeScript#315
shubham-01-star wants to merge 14 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)

Add 7 simple Mongoose models with no static methods:
- BotReport.ts: userId/reporterId refs, compound unique index
- VoteLog.ts: userId/postId refs, type enum (up|down)
- UserReport.ts: reportedUserId/reporterId refs, reason, status
- Domain.ts: key (unique, required), name
- Creator.ts: name (required), avatar, bio
- Content.ts: creatorId (ref Creator), domainId (ref Domain), title, url
- Collection.ts: userId, name (required), description (String, bug fix), postIds[]

All schemas use Mongoose 9.x conventions with { timestamps: true }.
No deprecated options (useNewUrlParser etc.) anywhere.
Types imported from ~/types/mongoose.
Add 3 Mongoose models with Mongoose statics and indexes:
- Group.ts: creatorId/adminIds/allowedUserIds, privacy enum,
  static findByCreatorId()
- UserInvite.ts: email (lowercase/trim), code, status, expiresAt,
  indexes on {email}, {code}, {status},
  static findByEmail()
- UserReputation.ts: userId (unique), 4 score fields, 10 nested
  metrics fields, indexes on {overallScore:-1}/{lastCalculated},
  statics findByUserId() + calculateScore() with dynamic import()
  to break circular dependency with reputation.ts

All schemas use { timestamps: true } + Mongoose 9.x conventions.
Re-exports BotReport, Collection, Content, Creator, Domain,
Group, UserInvite, UserReport, UserReputation, VoteLog from index.ts
79 tests across 12 model test files covering:
- Create / Read / Update / Delete for each model
- Static method tests (findByEmail, findByCreatorId,
  findByUserId, calculateScore)
All tests pass: 362/362 suite-wide
- Add 16 missing fields to User interface (common.ts) matching Prisma schema:
  bio, location, website, companyName, plan, stripeCustomerId, tokens,
  _wallet, status, _votesId, favorited, emailVerified, isModerator,
  blockedUserIds, settings, lastLogin
- Add ObjectId overrides in UserDocument (mongoose.ts)
- Expand User.ts Mongoose schema with all new fields and indexes
- Add User barrel export in models/index.ts
- Install stripe@20.4.1 as dependency
- Replace require('stripe') with proper ES import in getStripeAuth.ts
- Use Stripe SDK types (Stripe.Customer, Stripe.PaymentMethod,
  Stripe.PaymentMethodCreateParams.Card) across all Stripe utilities
- Remove all Record<string, unknown> workarounds and inline type casts
- Update stripe.test.ts to use ES module mock format (remove virtual: true)
- Add comprehensive User.test.ts with 24 unit tests

All 386 tests pass, tsc --noEmit clean.
@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

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