projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix king tracking in Fusion variant
[vchess.git]
/
server
/
models
/
Problem.js
diff --git
a/server/models/Problem.js
b/server/models/Problem.js
index
2d29520
..
cc74006
100644
(file)
--- a/
server/models/Problem.js
+++ b/
server/models/Problem.js
@@
-12,6
+12,7
@@
const db = require("../utils/database");
*/
const ProblemModel = {
*/
const ProblemModel = {
+
checkProblem: function(p) {
return (
p.id.toString().match(/^[0-9]+$/) &&
checkProblem: function(p) {
return (
p.id.toString().match(/^[0-9]+$/) &&
@@
-63,8
+64,10
@@
const ProblemModel = {
});
},
});
},
- 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 " +
@@
-72,19
+75,22
@@
const ProblemModel = {
"fen = '" + prob.fen + "'," +
"instruction = ?," +
"solution = ? " +
"fen = '" + prob.fen + "'," +
"instruction = ?," +
"solution = ? " +
-
"WHERE id = " + prob.id + " AND uid = " + uid
;
+
whereClause
;
db.run(query, [prob.instruction, prob.solution]);
});
},
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);
});
- },
-}
+ }
+
+};
module.exports = ProblemModel;
module.exports = ProblemModel;