projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix corr notification bug
[vchess.git]
/
server
/
models
/
Problem.js
diff --git
a/server/models/Problem.js
b/server/models/Problem.js
index
5c9af0b
..
eef4270
100644
(file)
--- 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 * " +
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);
});
});
cb(err, problems);
});
});
@@
-50,14
+57,16
@@
const ProblemModel = {
"SELECT * " +
"FROM Problems " +
"WHERE id = " + id;
"SELECT * " +
"FROM Problems " +
"WHERE id = " + id;
- db.get(query, (err,problem) => {
+ db.get(query, (err,
problem) => {
cb(err, problem);
});
});
},
cb(err, problem);
});
});
},
- safeUpdate: function(prob, uid) {
+ safeUpdate: function(prob, uid
, devs
) {
db.serialize(function() {
db.serialize(function() {
+ let whereClause = "WHERE id = " + prob.id;
+ if (!devs.includes(uid)) whereClause += " AND uid = " + uid;
const query =
"UPDATE Problems " +
"SET " +
const query =
"UPDATE Problems " +
"SET " +
@@
-65,16
+74,18
@@
const ProblemModel = {
"fen = '" + prob.fen + "'," +
"instruction = ?," +
"solution = ? " +
"fen = '" + prob.fen + "'," +
"instruction = ?," +
"solution = ? " +
-
"WHERE id = " + prob.id + " AND uid = " + uid
;
- db.run(query, [prob.instruction,prob.solution]);
+
whereClause
;
+ db.run(query, [prob.instruction,
prob.solution]);
});
},
});
},
- safeRemove: function(id, uid) {
+ safeRemove: function(id, uid
, devs
) {
db.serialize(function() {
db.serialize(function() {
+ let whereClause = "WHERE id = " + id;
+ if (!devs.includes(uid)) whereClause += " AND uid = " + uid;
const query =
"DELETE FROM Problems " +
const query =
"DELETE FROM Problems " +
-
"WHERE id = " + id + " AND uid = " + uid
;
+
whereClause
;
db.run(query);
});
},
db.run(query);
});
},