mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
Fix sync ui
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { requireAuth, AuthenticatedRequest } from '@/lib/middleware/auth';
|
||||
import { prisma } from '@/lib/db';
|
||||
import { getJobQueueService } from '@/lib/services/job-queue.service';
|
||||
import { RMABLogger } from '@/lib/utils/logger';
|
||||
import { z } from 'zod';
|
||||
@@ -30,6 +31,21 @@ export async function POST(request: NextRequest) {
|
||||
const body = await request.json().catch(() => ({}));
|
||||
const { shelfId, shelfType } = SyncSchema.parse(body);
|
||||
|
||||
// Set lastSyncAt to null so the frontend SWR refresh catches the "Syncing..." state immediately
|
||||
if (!shelfType || shelfType === 'goodreads') {
|
||||
await prisma.goodreadsShelf.updateMany({
|
||||
where: { userId: req.user.id, ...(shelfId ? { id: shelfId } : {}) },
|
||||
data: { lastSyncAt: null },
|
||||
});
|
||||
}
|
||||
|
||||
if (!shelfType || shelfType === 'hardcover') {
|
||||
await prisma.hardcoverShelf.updateMany({
|
||||
where: { userId: req.user.id, ...(shelfId ? { id: shelfId } : {}) },
|
||||
data: { lastSyncAt: null },
|
||||
});
|
||||
}
|
||||
|
||||
const jobQueue = getJobQueueService();
|
||||
|
||||
// Trigger sync job with userId filter
|
||||
|
||||
Reference in New Issue
Block a user