30d7f321d3
Use local dates instead of UTC for day boundaries, and store an epoch timestamp alongside the date string. Streak alive check uses real elapsed time (<48h) which covers dateline crossings. Old data without timestamps falls back to date-string comparison so existing streaks are preserved.
23 lines
757 B
TypeScript
23 lines
757 B
TypeScript
import mongoose from 'mongoose';
|
|
|
|
const RosaryStreakSchema = new mongoose.Schema(
|
|
{
|
|
username: { type: String, required: true, unique: true },
|
|
length: { type: Number, required: true, default: 0 },
|
|
lastPrayed: { type: String, default: null }, // local YYYY-MM-DD
|
|
lastPrayedTs: { type: Number, default: null } // epoch ms for timezone-safe streak checks
|
|
},
|
|
{ timestamps: true }
|
|
);
|
|
|
|
interface IRosaryStreak {
|
|
username: string;
|
|
length: number;
|
|
lastPrayed: string | null;
|
|
lastPrayedTs: number | null;
|
|
}
|
|
|
|
let _model: mongoose.Model<IRosaryStreak>;
|
|
try { _model = mongoose.model<IRosaryStreak>("RosaryStreak"); } catch { _model = mongoose.model<IRosaryStreak>("RosaryStreak", RosaryStreakSchema); }
|
|
export const RosaryStreak = _model;
|