X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=server%2Fmodels%2FProblem.js;h=9978d76f108c97c25ca1ef6adc9bc372c6ed86c2;hp=bcbefc5f251300c0d2ea64a2be658f62434d97fe;hb=a9e7935190d8fc112e674add05e86b8d0152e8df;hpb=68e19a449db7a12e0a168e99cd750d985c983ba1 diff --git a/server/models/Problem.js b/server/models/Problem.js index bcbefc5f..9978d76f 100644 --- a/server/models/Problem.js +++ b/server/models/Problem.js @@ -33,12 +33,16 @@ const ProblemModel = { }); }, - getNext: function(cursor, 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 " + "WHERE added < " + cursor + " " + + condition + "ORDER BY added DESC " + "LIMIT 20"; //TODO: 20 is arbitrary db.all(query, (err, problems) => { @@ -59,8 +63,10 @@ const ProblemModel = { }); }, - safeUpdate: function(prob, uid) { + safeUpdate: function(prob, uid, devs) { db.serialize(function() { + let whereClause = "WHERE id = " + prob.id; + if (!devs.includes(uid)) whereClause += " AND uid = " + uid; const query = "UPDATE Problems " + "SET " + @@ -68,16 +74,18 @@ const ProblemModel = { "fen = '" + prob.fen + "'," + "instruction = ?," + "solution = ? " + - "WHERE id = " + prob.id + " AND uid = " + uid; + whereClause; db.run(query, [prob.instruction, prob.solution]); }); }, - safeRemove: function(id, uid) { + safeRemove: function(id, uid, devs) { db.serialize(function() { + let whereClause = "WHERE id = " + prob.id; + if (!devs.includes(uid)) whereClause += " AND uid = " + uid; const query = "DELETE FROM Problems " + - "WHERE id = " + id + " AND uid = " + uid; + whereClause; db.run(query); }); },