Skip to content

Commit dc5d2e5

Browse files
authored
fix: add lastSeen and visitCount to UserSchema to prevent silent data loss (JhaSourav07#3125)
## Description This PR resolves the Silent Data Loss issue in the `/api/track-user` endpoint caused by Mongoose's `strict: true` behavior. Changes made: - Added `lastSeen` (Date) and `visitCount` (Number) to the `UserSchema` in `models/User.ts`. - Updated the `IUser` TypeScript interface to include `lastSeen?: Date` and `visitCount?: number` to maintain type safety. This ensures that analytics metrics are no longer silently dropped during upsert operations and are successfully persisted to MongoDB. Fixes JhaSourav07#3015 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents fceca8b + d09acb7 commit dc5d2e5

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

models/User.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import mongoose, { Document, Model, Schema } from 'mongoose';
33
export interface IUser extends Document {
44
username: string;
55
createdAt: Date;
6+
lastSeen?: Date;
7+
visitCount: number;
68
}
79

8-
const UserSchema: Schema = new Schema({
10+
const UserSchema: Schema<IUser> = new Schema<IUser>({
911
username: {
1012
type: String,
1113
required: true,
@@ -17,6 +19,13 @@ const UserSchema: Schema = new Schema({
1719
type: Date,
1820
default: Date.now,
1921
},
22+
lastSeen: {
23+
type: Date,
24+
},
25+
visitCount: {
26+
type: Number,
27+
default: 0,
28+
},
2029
});
2130

2231
export const User: Model<IUser> = mongoose.models.User || mongoose.model<IUser>('User', UserSchema);

0 commit comments

Comments
 (0)