feat: Implement writing streak tracking, add chapter API routes, and introduce a BookSettings component with i18n support.
This commit is contained in:
41
test-streak.ts
Normal file
41
test-streak.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { updateWritingStreak } from './src/lib/streak';
|
||||
import { prisma } from './src/lib/prisma';
|
||||
|
||||
async function main() {
|
||||
// 1. Get the first user
|
||||
const user = await prisma.user.findFirst();
|
||||
if (!user) {
|
||||
console.log("No user found.");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Original streak for ${user.email}:`, user.writingStreak, "Last write date:", user.lastWriteDate);
|
||||
|
||||
// 2. Simulate setting lastWriteDate to yesterday
|
||||
const yesterday = new Date();
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
|
||||
await prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: {
|
||||
lastWriteDate: yesterday,
|
||||
writingStreak: 5 // let's pretend it was 5
|
||||
}
|
||||
});
|
||||
|
||||
console.log("Updated lastWriteDate to yesterday, streak is 5.");
|
||||
|
||||
// 3. Call our function to update the streak (as if they wrote today)
|
||||
console.log("Calling updateWritingStreak...");
|
||||
await updateWritingStreak(user.id);
|
||||
|
||||
// 4. Verify the new values
|
||||
const updatedUser = await prisma.user.findUnique({
|
||||
where: { id: user.id },
|
||||
select: { writingStreak: true, lastWriteDate: true }
|
||||
});
|
||||
|
||||
console.log(`New streak:`, updatedUser?.writingStreak, "Last write date:", updatedUser?.lastWriteDate);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
Reference in New Issue
Block a user