Update various configuration files, components, and assets; enhance notification system and API endpoints; improve documentation and styles across the application.
This commit is contained in:
71
server/api/notifications/batch/stats.get.js
Normal file
71
server/api/notifications/batch/stats.get.js
Normal file
@@ -0,0 +1,71 @@
|
||||
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 {
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user