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:
54
server/api/notifications/delivery/sms-config.get.js
Normal file
54
server/api/notifications/delivery/sms-config.get.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import prisma from "~/server/utils/prisma";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const user = event.context.user;
|
||||
if (!user) {
|
||||
throw createError({
|
||||
statusCode: 401,
|
||||
statusMessage: "Authentication required",
|
||||
});
|
||||
}
|
||||
const smsConfig = await prisma.notification_delivery_config.findFirst({
|
||||
where: { channel_type: 'sms' },
|
||||
select: {
|
||||
is_enabled: true,
|
||||
provider: true,
|
||||
provider_config: true,
|
||||
status: true,
|
||||
success_rate: true,
|
||||
created_at: true,
|
||||
updated_at: true
|
||||
}
|
||||
});
|
||||
if (!smsConfig) {
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
enabled: false,
|
||||
provider: 'twilio',
|
||||
status: 'Not Configured',
|
||||
successRate: 0
|
||||
}
|
||||
};
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
enabled: smsConfig.is_enabled,
|
||||
provider: smsConfig.provider,
|
||||
status: smsConfig.status,
|
||||
successRate: smsConfig.success_rate,
|
||||
config: smsConfig.provider_config
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error fetching SMS configuration:', error);
|
||||
if (error.statusCode) throw error;
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to fetch SMS configuration'
|
||||
});
|
||||
} finally {
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user