first commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// src/stores/saasHealthStore.js
|
||||
import { defineStore } from 'pinia'
|
||||
import { supabase } from '@/lib/supabase/client'
|
||||
|
||||
export const useSaasHealthStore = defineStore('saasHealth', {
|
||||
state: () => ({
|
||||
mismatchCount: 0,
|
||||
loading: false,
|
||||
lastLoadedAt: null
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async loadMismatchCount ({ force = false } = {}) {
|
||||
if (this.loading) return
|
||||
if (!force && this.lastLoadedAt && (Date.now() - this.lastLoadedAt) < 30_000) return // cache 30s
|
||||
|
||||
this.loading = true
|
||||
try {
|
||||
const { count, error } = await supabase
|
||||
.from('v_subscription_feature_mismatch')
|
||||
.select('*', { count: 'exact', head: true })
|
||||
|
||||
if (error) throw error
|
||||
this.mismatchCount = Number(count || 0)
|
||||
this.lastLoadedAt = Date.now()
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user