migrate Comment model to TypeScript and expand schema (Issue 7.21)#314
Conversation
|
@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. |
Om7035
left a comment
There was a problem hiding this comment.
File: quotevote-backend/app/data/models/Comment.ts
Inline comment A (on/near findByPostId static)
findByPostId(postId: string) should validate/cast ObjectId input before querying.
Suggest using Types.ObjectId.isValid(postId) and converting to new Types.ObjectId(postId) to avoid malformed query inputs and inconsistent behavior.
Inline comment B (on/near findByUserId static)
Same concern here: please validate/cast userId to ObjectId before querying.
Returning [] for invalid IDs is safer than hitting Mongo with invalid types.
Inline comment C (on/near statics + sort/filter query shape)
These statics filter by deleted != true and sort by created.
Please add compound indexes for these paths to avoid collection scans under load (e.g. { postId: 1, deleted: 1, created: 1 } and { userId: 1, deleted: 1, created: -1 }).
Inline comment D (on/near text index)
Text index on comments is useful, but please confirm this is required now and measured.
Text indexes increase write/index maintenance cost and should be intentional with query usage.
File: quotevote-backend/app/types/common.ts
Inline comment E (on/near postId?: string)
postId became optional — can we confirm this matches product rules?
If comments can exist without post linkage, service/API validators and consumers need explicit handling; otherwise this should remain required.
Inline comment F (on/near startWordIndex / endWordIndex required)
Making these required is a good consistency move, but please confirm all creation flows now populate both values.
Add/update tests for any API paths creating comments to prevent runtime regressions.
File: quotevote-backend/app/types/mongoose.ts
Inline comment G (on/near CommentDocument typing changes)
The type now omits and redefines fields (created, optional postId).
Please ensure this stays aligned with actual mongoose schema/runtime docs to avoid TS saying “safe” while runtime diverges.
File: quotevote-backend/tests/unit/models/Comment.test.ts
Inline comment H (on/near beforeAll setup comment)
Current setup comment suggests uncertainty around DB initialization.
For model statics/schema changes, please add deterministic integration tests (mongodb-memory-server) rather than relying only on mocks/spies.
Inline comment I (on/near mocked static tests)
These tests validate query construction, which is useful, but they don’t prove schema/index behavior.
Please add integration assertions for soft-delete filtering, sort order, and invalid ObjectId handling.
File: quotevote-backend/package.json (and lockfile)
Inline comment J (on Stripe dependency/type changes)
Stripe dependency/type updates appear unrelated to Comment migration scope.
Please move to a separate PR unless there is a strict dependency reason and it’s documented in this PR description.
Summary
Migrates the legacy
CommentModel.jsto strongly-typed TypeScript inquotevote-next.Changes
deleted, madepostIdoptional, andstartWordIndex/endWordIndexrequired incommon.tsandmongoose.tsto match the legacy schema.app/data/models/Comment.tswith the full Mongoose schema, including text indexes and statics forfindByPostId/findByUserId.Comment.test.tsto verify schema validation and static queries.All 405 tests,
tsc --noEmit, andpnpm lintpass successfully.