diff --git a/src/pages/Admin/VisitsView.vue b/src/pages/Admin/VisitsView.vue index c2bf260d..f8157ee6 100644 --- a/src/pages/Admin/VisitsView.vue +++ b/src/pages/Admin/VisitsView.vue @@ -10,7 +10,7 @@ import { useAppStore } from 'stores/app'; import { storeToRefs } from 'pinia'; const { t } = useI18n(); -const jApi = inject('jApi'); +const api = inject('api'); const route = useRoute(); const router = useRouter(); const appStore = useAppStore(); @@ -24,28 +24,21 @@ const visitsData = ref(null); const getVisits = async () => { try { loading.value = true; - const [visitsResponse] = await jApi.query( - `SELECT browser, - MIN(CAST(version AS DECIMAL(4,1))) minVersion, - MAX(CAST(version AS DECIMAL(4,1))) maxVersion, - MAX(c.stamp) lastVisit, - COUNT(DISTINCT c.id) visits, - SUM(a.firstAccessFk = c.id AND v.firstAgentFk = a.id) newVisits - FROM visitUser e - JOIN visitAccess c ON c.id = e.accessFk - JOIN visitAgent a ON a.id = c.agentFk - JOIN visit v ON v.id = a.visitFk - WHERE c.stamp BETWEEN TIMESTAMP(#from,'00:00:00') AND TIMESTAMP(#to,'23:59:59') - GROUP BY browser ORDER BY visits DESC`, - { + + const { data } = await api.get('visitUsers/getVisits', { + params: { from: date(from.value), to: date(to.value) } - ); - visitsData.value = visitsResponse; - loading.value = false; + }); + + if (!data || !data.length) return; + + visitsData.value = data[0]; } catch (error) { console.error('Error getting visits:', error); + } finally { + loading.value = false; } };