71 lines
1.7 KiB
JavaScript
71 lines
1.7 KiB
JavaScript
import prisma from "~/server/utils/prisma";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
// Since there's no explicit batch table in the schema, we'll simulate this by
|
|
// counting notifications with batch-related properties
|
|
|
|
// Get current date and set to start of day
|
|
const today = new Date();
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
// Define what constitutes a "batch" notification (likely based on delivery_type or audience_type)
|
|
const batchWhere = {
|
|
delivery_type: "batch",
|
|
};
|
|
|
|
// Get batch stats
|
|
const [pending, processing, completed, failed] = await Promise.all([
|
|
// Pending batches (draft or scheduled)
|
|
prisma.notifications.count({
|
|
where: {
|
|
...batchWhere,
|
|
status: {
|
|
in: ["draft", "scheduled"],
|
|
},
|
|
},
|
|
}),
|
|
// Processing batches
|
|
prisma.notifications.count({
|
|
where: {
|
|
...batchWhere,
|
|
status: "processing",
|
|
},
|
|
}),
|
|
// Completed batches
|
|
prisma.notifications.count({
|
|
where: {
|
|
...batchWhere,
|
|
status: "completed",
|
|
},
|
|
}),
|
|
// Failed batches
|
|
prisma.notifications.count({
|
|
where: {
|
|
...batchWhere,
|
|
status: "failed",
|
|
},
|
|
}),
|
|
]);
|
|
|
|
return {
|
|
success: true,
|
|
data: {
|
|
pending,
|
|
processing,
|
|
completed,
|
|
failed,
|
|
},
|
|
};
|
|
} catch (error) {
|
|
console.error("Error fetching batch stats:", error);
|
|
throw createError({
|
|
statusCode: 500,
|
|
statusMessage: "Failed to fetch batch statistics",
|
|
data: {
|
|
error: error.message,
|
|
},
|
|
});
|
|
} finally {
|
|
}
|
|
});
|