mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-17 23:12:09 +01:00
shit
This commit is contained in:
50
lib/admin-service.ts
Normal file
50
lib/admin-service.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { getServerSession } from "next-auth";
|
||||
import { authOptions } from "../app/api/auth/[...nextauth]/route"; // Adjust path as needed
|
||||
import { prisma } from "./prisma";
|
||||
import { processUnprocessedSessions } from "./processingSchedulerNoCron";
|
||||
|
||||
export async function getAdminUser() {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
if (!session?.user) {
|
||||
throw new Error("Not logged in");
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { email: session.user.email as string },
|
||||
include: { company: true },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new Error("No user found");
|
||||
}
|
||||
|
||||
if (user.role !== "admin") {
|
||||
throw new Error("Admin access required");
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
export async function triggerSessionProcessing(batchSize?: number, maxConcurrency?: number) {
|
||||
const unprocessedCount = await prisma.session.count({
|
||||
where: {
|
||||
processed: false,
|
||||
messages: { some: {} }, // Must have messages
|
||||
},
|
||||
});
|
||||
|
||||
if (unprocessedCount === 0) {
|
||||
return { message: "No unprocessed sessions found", unprocessedCount: 0, processedCount: 0 };
|
||||
}
|
||||
|
||||
processUnprocessedSessions(batchSize, maxConcurrency)
|
||||
.then(() => {
|
||||
console.log(`[Manual Trigger] Processing completed`);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(`[Manual Trigger] Processing failed:`, error);
|
||||
});
|
||||
|
||||
return { message: `Started processing ${unprocessedCount} unprocessed sessions`, unprocessedCount };
|
||||
}
|
||||
Reference in New Issue
Block a user