I. js / pasatiempoModifica.js

1
import { ALMACEN_PASATIEMPO, Bd } from "./Bd.js"
2
import { bdEjecuta } from "./lib/bdEjecuta.js"
3
import { recibeTextoObligatorio } from "./lib/recibeTextoObligatorio.js"
4
import { pasatiempoBusca } from "./pasatiempoBusca.js"
5
6
/**
7
 * @param {SubmitEvent} event
8
 * @param {string} id
9
 */
10
export async function pasatiempoModifica(event, id) {
11
12
 event.preventDefault()
13
 const target = event.target
14
15
 if (!(target instanceof HTMLFormElement))
16
  throw new Error("target no es de tipo form.")
17
18
 const formData = new FormData(target)
19
20
 const nombre = recibeTextoObligatorio(formData, "nombre")
21
22
 const anterior = await pasatiempoBusca(id)
23
24
 if (anterior !== undefined) {
25
26
  anterior.PAS_NOMBRE = nombre
27
  anterior.PAS_MODIFICACION = Date.now()
28
29
  await bdEjecuta(Bd, [ALMACEN_PASATIEMPO], transaccion => {
30
   const almacenPasatiempo = transaccion.objectStore(ALMACEN_PASATIEMPO)
31
   almacenPasatiempo.put(anterior)
32
  })
33
34
 location.href = "index.html"
35
36
 }
37
38
}
skip_previous skip_next