X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fmodels%2FProblem.js;h=2d29520fdce33002634d1b1cdc2a7a9bd9963f83;hb=84fc0f02d3d399af66c40b3e9994f67b415ffd0e;hp=5c9af0b1803d6ff675d4970804bbfd5f74a4d48a;hpb=0234201fb338fc239d6f613c677fa932c7c3697c;p=vchess.git diff --git a/server/models/Problem.js b/server/models/Problem.js index 5c9af0b1..2d29520f 100644 --- a/server/models/Problem.js +++ b/server/models/Problem.js @@ -33,12 +33,19 @@ const ProblemModel = { }); }, - getAll: function(cb) { + getNext: function(uid, onlyMine, cursor, cb) { + let condition = ""; + if (onlyMine) condition = "AND uid = " + uid + " "; + else if (!!uid) condition = "AND uid <> " + uid + " "; db.serialize(function() { const query = "SELECT * " + - "FROM Problems"; - db.all(query, (err,problems) => { + "FROM Problems " + + "WHERE added < " + cursor + " " + + condition + + "ORDER BY added DESC " + + "LIMIT 20"; //TODO: 20 is arbitrary + db.all(query, (err, problems) => { cb(err, problems); }); }); @@ -50,7 +57,7 @@ const ProblemModel = { "SELECT * " + "FROM Problems " + "WHERE id = " + id; - db.get(query, (err,problem) => { + db.get(query, (err, problem) => { cb(err, problem); }); }); @@ -66,7 +73,7 @@ const ProblemModel = { "instruction = ?," + "solution = ? " + "WHERE id = " + prob.id + " AND uid = " + uid; - db.run(query, [prob.instruction,prob.solution]); + db.run(query, [prob.instruction, prob.solution]); }); },