shareUser
This commit is contained in:
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
<q-card-actions>
|
<q-card-actions>
|
||||||
<q-btn flat>Editar</q-btn>
|
<q-btn flat>Editar</q-btn>
|
||||||
<q-btn flat>Compartir</q-btn>
|
<q-btn flat @click="shareUser(lista.id)">Compartir</q-btn>
|
||||||
<q-space></q-space>
|
<q-space></q-space>
|
||||||
<q-btn class="bg-negative q-mr-md" flat>Borrar</q-btn>
|
<q-btn class="bg-negative q-mr-md" flat>Borrar</q-btn>
|
||||||
</q-card-actions>
|
</q-card-actions>
|
||||||
@@ -66,7 +66,6 @@ const getListas = async () => {
|
|||||||
.from('listas')
|
.from('listas')
|
||||||
.select(`*, profiles(*),items(is_done)`)
|
.select(`*, profiles(*),items(is_done)`)
|
||||||
if (error) throw error
|
if (error) throw error
|
||||||
console.log('listas', listas)
|
|
||||||
store.listas = listas
|
store.listas = listas
|
||||||
ordenarArray(store.listas)
|
ordenarArray(store.listas)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -174,6 +173,77 @@ const unShareUser = async (user_id, lista_id, email) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getProfileByEmail = async (email) => {
|
||||||
|
try {
|
||||||
|
const { data, error } = await supabase
|
||||||
|
.from('profiles')
|
||||||
|
.select()
|
||||||
|
.eq('email', email.trim())
|
||||||
|
if (error) throw error
|
||||||
|
return data[0]
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
$q.notify({
|
||||||
|
type: 'negative',
|
||||||
|
message: error.message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const shareUser = async (id) => {
|
||||||
|
$q.dialog({
|
||||||
|
title: 'Escriba',
|
||||||
|
message: 'Email del usuario',
|
||||||
|
html: true,
|
||||||
|
prompt: {
|
||||||
|
model: '',
|
||||||
|
isValid: val => val.length > 5, // << here is the magic
|
||||||
|
type: 'text'
|
||||||
|
},
|
||||||
|
ok: {
|
||||||
|
push: true,
|
||||||
|
|
||||||
|
},
|
||||||
|
cancel: {
|
||||||
|
push: true,
|
||||||
|
},
|
||||||
|
persistent: true
|
||||||
|
}).onOk(async (email) => {
|
||||||
|
try {
|
||||||
|
const profile = await getProfileByEmail(email)
|
||||||
|
if (profile.email === store.user.email) {
|
||||||
|
$q.notify({
|
||||||
|
type: 'negative',
|
||||||
|
message: 'No puede compartir la lista con usted mismo'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const { error } = await supabase
|
||||||
|
.from('share')
|
||||||
|
.insert([
|
||||||
|
{ user_id: profile.id, lista_id: id },
|
||||||
|
])
|
||||||
|
.select()
|
||||||
|
if (error) throw error
|
||||||
|
store.listas.filter(l => l.id === id)[0].profiles.push(profile)
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
if (error.message.includes('profile is undefined')) {
|
||||||
|
$q.notify({
|
||||||
|
type: 'negative',
|
||||||
|
message: 'El email no existe en la base de datos'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
$q.notify({
|
||||||
|
type: 'negative',
|
||||||
|
message: error.message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getListas()
|
getListas()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user