Skip to content

feat(backend): 7.18 – Migrate simple Mongoose models to TypeScript#301

Open
shubham-01-star wants to merge 6 commits intoQuoteVote:mainfrom
shubham-01-star:feature/7.18-migrate-simple-models-ts
Open

feat(backend): 7.18 – Migrate simple Mongoose models to TypeScript#301
shubham-01-star wants to merge 6 commits intoQuoteVote:mainfrom
shubham-01-star:feature/7.18-migrate-simple-models-ts

Conversation

@shubham-01-star
Copy link
Copy Markdown
Collaborator

Summary
Implements task 7.18 — adds 10 missing TypeScript Mongoose models and CRUD unit tests.

Changes
Phase 1 – Simple models (no statics) BotReport, VoteLog, UserReport, Domain, Creator, Content, Collection

Phase 2 – Models with statics Group (findByCreatorId), UserInvite (findByEmail), UserReputation (findByUserId, calculateScore)

Phase 3 – Barrel export app/data/models/index.ts updated to export all 10 new models

Phase 4 – Unit tests 79 CRUD tests across 12 model test files

Notes
All types imported from shared mongoose types file (pre-existing)
No deprecated Mongoose options anywhere — clean 9.x conventions
findOneAndRemove not used anywhere
UserReputation calculateScore uses dynamic import to avoid circular dependency with reputation.ts
Collection description uses String type (fixes old JS bug where it was Number)
Test Results
362 tests passed, 40 suites — 0 failures Type check passes with zero errors

Closes #7.18

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
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 24, 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 24, 2026

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

Project Deployment Actions Updated (UTC)
quotevote Ready Ready Preview, Comment Mar 24, 2026 3:35am

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.6 Configure Environment Variables & Project Path Structure

1 participant