This commit is contained in:
Leonardo
2026-03-06 06:37:13 -03:00
parent d58dc21297
commit f733db8436
146 changed files with 43436 additions and 12779 deletions
+16
View File
@@ -13,6 +13,20 @@ async function getOwnerId () {
return uid
}
async function getActiveTenantId (uid) {
const { data, error } = await supabase
.from('tenant_members')
.select('tenant_id')
.eq('user_id', uid)
.eq('status', 'active')
.order('created_at', { ascending: false })
.limit(1)
.single()
if (error) throw error
if (!data?.tenant_id) throw new Error('Tenant não encontrado.')
return data.tenant_id
}
function normalizeNome (s) {
return String(s || '').trim().toLowerCase().replace(/\s+/g, ' ')
}
@@ -79,6 +93,7 @@ export async function listGroupsWithCounts () {
export async function createGroup (nome, cor = null) {
const ownerId = await getOwnerId()
const tenantId = await getActiveTenantId(ownerId)
const raw = String(nome || '').trim()
if (!raw) throw new Error('Nome do grupo é obrigatório.')
@@ -100,6 +115,7 @@ export async function createGroup (nome, cor = null) {
const payload = {
owner_id: ownerId,
tenant_id: tenantId,
nome: raw,
cor: cor || null
}