Sample avap code

This commit is contained in:
rafa-ruiz 2026-03-04 20:21:27 -08:00
parent 1c9ee8d5dd
commit 8379033900
32 changed files with 146 additions and 0 deletions

View File

@ -0,0 +1,3 @@
nivel = 5
es_admin = nivel >= 10
addResult(es_admin)

View File

@ -0,0 +1,4 @@
subtotal = 150.50
iva = subtotal * 0.21
total = subtotal + iva
addResult(total)

View File

@ -0,0 +1,6 @@
startLoop(i,1,10)
item = "item_%s" % i
AddvariableToJSON(item,'valor_generado',mi_json)
endLoop()
addResult(mi_json)

View File

@ -0,0 +1,7 @@
registros = ['1','2','3']
getListLen(registros, total)
contador = 0
startLoop(idx, 0, 2)
actual = registros[int(idx)]
endLoop()
addResult(actual)

View File

@ -0,0 +1,2 @@
getDateTime("", 86400, "UTC", expira)
addResult(expira)

View File

@ -0,0 +1,2 @@
addParam("client_id", id_interno)
addResult(id_interno)

View File

@ -0,0 +1,3 @@
addParam(emails,emails)
getQueryParamList(lista_correos)
addResult(lista_correos)

View File

@ -0,0 +1,5 @@
addParam("lang", l)
if(l, "es", "=")
addVar(msg, "Hola")
end()
addResult(msg)

View File

@ -0,0 +1,3 @@
nombre = "Sistema"
log = "Evento registrado por: %s" % nombre
addResult(log)

View File

@ -0,0 +1,4 @@
datos_cliente = "datos"
addVar(clave, "cliente_vip")
AddvariableToJSON(clave, datos_cliente, mi_json_final)
addResult(mi_json_final)

View File

@ -0,0 +1,3 @@
addParam("data_list", mi_lista)
getListLen(mi_lista, cantidad)
addResult(cantidad)

View File

@ -0,0 +1,2 @@
stampToDatetime(1708726162, "%d/%m/%Y", 0, fecha_human)
addResult(fecha_human)

View File

@ -0,0 +1,7 @@
addParam(sal_par,saldo)
if(saldo, 0, ">")
permitir = True
else()
permitir = False
end()
addResult(permitir)

View File

@ -0,0 +1,6 @@
addParam(userrype, user_type)
addParam(sells, compras)
if(None, None, " user_type == 'VIP' or compras > 100")
addVar(descuento, 0.20)
end()
addResult(descuento)

View File

@ -0,0 +1,2 @@
getDateTime("%Y-%m-%d %H:%M:%S", 0, "Europe/Madrid", sql_date)
addResult(sql_date)

View File

@ -0,0 +1,6 @@
function suma(a, b){
total = a + b
return(total)
}
resultado = suma(10, 20)
addResult(resultado)

View File

@ -0,0 +1,9 @@
function es_valido(token){
response = False
if(token, "SECRET", "=")
response = True
end()
return(response)
}
autorizado = es_valido("SECRET")
addResult(autorizado)

View File

@ -0,0 +1,2 @@
randomString("[A-Z]\d", 32, token_seguridad)
addResult(token_seguridad)

View File

@ -0,0 +1,2 @@
encodeSHA256("payload_data", checksum)
addResult(checksum)

View File

@ -0,0 +1,2 @@
addVar(mensaje, "Hola mundo desde AVAP")
addResult(mensaje)

View File

@ -0,0 +1,6 @@
addParam(password,pass_nueva)
pass_antigua = "password"
if(pass_nueva, pass_antigua, "!=")
addVar(cambio, "Contraseña actualizada")
end()
addResult(cambio)

View File

@ -0,0 +1,2 @@
replace("REF_1234_OLD","OLD", "NEW", ref_actualizada)
addResult(ref_actualizada)

View File

@ -0,0 +1,5 @@
try()
ormDirect("UPDATE table_inexistente SET a=1", res)
exception(e)
addVar(_status,500)
addResult("Error de base de datos")

View File

@ -0,0 +1,2 @@
getDateTime("", 0, "UTC", ahora)
addResult(ahora)

View File

@ -0,0 +1,6 @@
ormCheckTable(tabla_pruebas,resultado_comprobacion)
if(resultado_comprobacion,False,'==')
ormCreateTable("username,age",'VARCHAR,INTEGER',tabla_pruebas,resultado_creacion)
end()
addResult(resultado_comprobacion)
addResult(resultado_creacion)

View File

@ -0,0 +1,14 @@
addParam("page", p)
addParam("size", s)
registros = ["u1", "u2", "u3", "u4", "u5", "u6"]
offset = int(p) * int(s)
limite = offset + int(s)
contador = 0
addResult(offset)
addResult(limite)
startLoop(i, 2, limite)
actual = registros[int(i)]
titulo = "reg_%s" % i
AddvariableToJSON(titulo, actual, pagina_json)
endLoop()
addResult(pagina_json)

View File

@ -0,0 +1,3 @@
addVar(base, 1000)
addVar(copia, $base)
addResult(copia)

View File

@ -0,0 +1,4 @@
addVar(code, 200)
addVar(status, "Success")
addResult(code)
addResult(status)

View File

@ -0,0 +1,8 @@
encontrado = False
startLoop(i, 1, 10)
if(i, 5, "==")
encontrado = True
i = 11
end()
endLoop()
addResult(encontrado)

View File

@ -0,0 +1,5 @@
try()
RequestGet("https://api.test.com/data", 0, 0, respuesta)
exception(e)
addVar(error_trace, "Fallo de conexión: %s" % e)
addResult(error_trace)

View File

@ -0,0 +1,6 @@
addParam("api_key", key)
if(key, None, "==")
addVar(_status, 403)
addVar(error, "Acceso denegado: falta API KEY")
addResult(error)
end()

View File

@ -0,0 +1,5 @@
addParam("rol", r)
if(r, ["admin", "editor", "root"], "in")
acceso = True
end()
addResult(acceso)