-
Notifications
You must be signed in to change notification settings - Fork 0
/
lrs.js
64 lines (53 loc) · 1.82 KB
/
lrs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//Funciones relacionadas con los registros de e-learning.
var db = require("./mysql").baseP;
const { logError } = require("./debug");
var check = require("./utility");
/**
* Introduce en la base de datos todos los registros recibidos
* @param {string} json
*/
async function AddListOfStatements(rawJSON)
{
let json = JSON.parse(rawJSON);
json = json["lista"];
for (var idx in json)
{
let result = await AddStatement(json[idx]);
if (result == -1) return {info:"Error..."};
}
return {info:"Correcto", res:"Registros almacenados con éxito."};
}
async function AddStatement(rawjson)
{
if (rawjson == undefined) return -1;
let json = JSON.parse(rawjson);
let actor = JSON.stringify(json["actor"]["mbox"]);
if(actor == undefined) return -1;
else actor = "'"+actor+"'";
let verb = JSON.stringify(json["verb"]["id"]);
if(verb == undefined) return -1;
else verb = "'"+verb+"'";
let obj = JSON.stringify(json["object"]["id"]);
if(obj == undefined) return -1;
else obj = "'"+obj+"'";
let res = JSON.stringify(json["result"]);
if(res == undefined) res = "null";
else res = "'"+res+"'";
let ctx = JSON.stringify(json["context"]);
if(ctx == undefined) ctx = "null";
else ctx = "'"+ctx+"'";
let time = json["timestamp"];
if(time == undefined) time = "null";
else time = "'"+time+"'";
let consulta = "INSERT INTO learningRecord (actor, verb, object, result, context, timestamp, whole_statement) VALUES ("+
actor+", "+verb+", "+obj+", "+res+", "+ctx+", "+time+", '"+rawjson+"')";
try {
await db.query(consulta);
return 1;
}
catch(err) {
logError("Error de consulta en al intentar almacenar el registro: "+err,'lsr');
return -1;
}
}
module.exports.AddListOfStatements = AddListOfStatements;