Files
arthome/app/composables/user-limit.ts
2024-08-30 18:15:07 +02:00

27 lines
642 B
TypeScript

export async function useUserLimit() {
const { user } = useUserSession()
const { categories } = await useCategories()
const { tabs } = await useTabs()
const hasPaidPlan = computed(() => user.value.subscription !== 'free')
function canCreateCategory() {
if (hasPaidPlan.value)
return true
return categories.value.length < 3
}
function canCreateTabInCategory(categoryId: number): boolean {
if (hasPaidPlan.value)
return true
return tabs.filter(tab => tab.categoryId === categoryId).length < 5
}
return {
hasPaidPlan,
userLimits,
canCreateCategory,
canCreateTabInCategory,
}
}