feat(#27): Set up consola logger, make use of log levels in backend and frontend
This commit is contained in:
@@ -2,6 +2,8 @@ import type { NotificationDto } from '~~/.api-client'
|
||||
import { useUserStore } from '~~/stores/useUserStore'
|
||||
|
||||
export const useNotification = () => {
|
||||
const logger = useLogger().withTag('notification')
|
||||
|
||||
const {
|
||||
getNotifications,
|
||||
getUnreadNotifications,
|
||||
@@ -22,7 +24,7 @@ export const useNotification = () => {
|
||||
|
||||
const fetchNotifications = async (page: number = 0, size: number = 20) => {
|
||||
if (!organizationId.value) {
|
||||
console.warn('No organization selected')
|
||||
logger.warn('No organization selected')
|
||||
return
|
||||
}
|
||||
isLoading.value = true
|
||||
@@ -31,7 +33,7 @@ export const useNotification = () => {
|
||||
notifications.value = response.content || []
|
||||
return response
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch notifications:', error)
|
||||
logger.error('Failed to fetch notifications:', error)
|
||||
throw error
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
@@ -40,7 +42,7 @@ export const useNotification = () => {
|
||||
|
||||
const fetchUnreadNotifications = async () => {
|
||||
if (!organizationId.value) {
|
||||
console.warn('No organization selected')
|
||||
logger.warn('No organization selected')
|
||||
return
|
||||
}
|
||||
try {
|
||||
@@ -48,14 +50,14 @@ export const useNotification = () => {
|
||||
unreadNotifications.value = response || []
|
||||
return response
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch unread notifications:', error)
|
||||
logger.error('Failed to fetch unread notifications:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const fetchUnreadCount = async () => {
|
||||
if (!userId.value || !organizationId.value) {
|
||||
console.warn('No user or organization selected')
|
||||
logger.warn('No user or organization selected')
|
||||
return
|
||||
}
|
||||
try {
|
||||
@@ -63,14 +65,14 @@ export const useNotification = () => {
|
||||
unreadCount.value = count || 0
|
||||
return count
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch unread count:', error)
|
||||
logger.error('Failed to fetch unread count:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const markAllAsRead = async () => {
|
||||
if (!organizationId.value) {
|
||||
console.warn('No organization selected')
|
||||
logger.warn('No organization selected')
|
||||
return
|
||||
}
|
||||
try {
|
||||
@@ -79,14 +81,14 @@ export const useNotification = () => {
|
||||
unreadNotifications.value = []
|
||||
notifications.value = notifications.value.map((n) => ({ ...n, isRead: true }))
|
||||
} catch (error) {
|
||||
console.error('Failed to mark all as read:', error)
|
||||
logger.error('Failed to mark all as read:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const markAsRead = async (notificationId: string) => {
|
||||
if (!organizationId.value) {
|
||||
console.warn('No organization selected')
|
||||
logger.warn('No organization selected')
|
||||
return
|
||||
}
|
||||
try {
|
||||
@@ -102,7 +104,7 @@ export const useNotification = () => {
|
||||
unreadCount.value--
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to mark notification as read:', error)
|
||||
logger.error('Failed to mark notification as read:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user