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:
37
server/api/notifications/categories.get.js
Normal file
37
server/api/notifications/categories.get.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import prisma from "~/server/utils/prisma";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
// Fetch notification categories from the database
|
||||
const categories = await prisma.notification_categories.findMany({
|
||||
select: {
|
||||
name: true,
|
||||
value: true,
|
||||
description: true,
|
||||
},
|
||||
orderBy: {
|
||||
name: 'asc'
|
||||
}
|
||||
});
|
||||
|
||||
// Transform the data to match the expected format
|
||||
const formattedCategories = categories.map(category => ({
|
||||
label: category.name,
|
||||
value: category.value,
|
||||
description: category.description
|
||||
}));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: formattedCategories
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching categories:', error)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to fetch categories'
|
||||
})
|
||||
} finally {
|
||||
// Disconnect Prisma client to avoid connection leaks
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user