untitled

Pasted Nov 12, 2026, 5:59 PM1 file49 lines

Scan to open on your phone

Point a camera at the QR code - it opens this exact paste, no app needed.

https://codepastes.com/zzgs6p7hvhhnny0q
untitled
package com.negocio.desinfectantes.data

import io.github.jan.supabase.postgrest.postgrest
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import kotlinx.serialization.json.jsonObject

class VentaSyncService {

    private val supabase = SupabaseClientProvider.client

    suspend fun sincronizarVenta(
        operacion: OperacionPendienteEntity
    ): Boolean {

        return try {
            val payload = Json.parseToJsonElement(operacion.payload)

            val respuesta = supabase.postgrest.rpc(
                function = "sincronizar_venta",
                parameters = buildJsonObject {
                    put("p_payload", payload)
                }
            )

            val resultado = Json.parseToJsonElement(respuesta.data)

            val correcto = resultado
                .jsonObject["ok"]
                ?.toString()
                ?.toBoolean() == true

            if (!correcto) {
                throw Exception("Supabase no confirmó el registro de la venta.")
            }

            true

        } catch (e: Exception) {
            throw Exception(
                "No se pudo sincronizar la venta: ${e.message}",
                e
            )
        }
    }
}

1,290 chars · codepastes.com