2019-05-02 22:04:06 +00:00
|
|
|
con = require("../index").con
|
2019-05-10 20:16:56 +00:00
|
|
|
hasher = require("sha-hasher")
|
|
|
|
enviarNotificacion = require("./enviarNotificacion").fun
|
2019-05-02 22:04:06 +00:00
|
|
|
|
|
|
|
export fun = (req, res) ->
|
|
|
|
|
|
|
|
subscripcion = req.body.subscripcion
|
2019-05-10 20:16:56 +00:00
|
|
|
hash = hasher.SHA256 subscripcion
|
2019-05-02 22:04:06 +00:00
|
|
|
|
2019-05-10 20:16:56 +00:00
|
|
|
query = "INSERT INTO navegadores (navegador_hash, susbscripcion) VALUES (?, ?)"
|
|
|
|
datos = [hash, subscripcion]
|
|
|
|
con.query query, datos, (err) ->
|
2019-05-02 22:04:06 +00:00
|
|
|
unless err?
|
2019-05-10 20:16:56 +00:00
|
|
|
enviarNotificacion subscripcion, "Subscripción exitosa",
|
|
|
|
"Ya puedes empezar a configurar las notificaciones de la página."
|
|
|
|
.then (respNot) ->
|
|
|
|
console.log JSON.stringify respNot
|
|
|
|
res.status(201).json {
|
|
|
|
exito: true,
|
|
|
|
payload:
|
|
|
|
hash: hash
|
|
|
|
}
|
|
|
|
.catch (errro) ->
|
|
|
|
console.log JSON.stringify errro
|
|
|
|
res.status(400).json {exito: false, razon: "Error al ejecutar notificacion :c"}
|
2019-05-02 22:04:06 +00:00
|
|
|
else
|
|
|
|
res.status(400).json {exito: false, razon: err}
|