- remove: function(id, uid)
- {
- db.serialize(function() {
- const query =
- "DELETE FROM Problems " +
- "WHERE id = " + id + " AND uid = " + uid;
- db.run(query);
- });
- },
+ 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 " +
+ "vid = " + prob.vid + "," +
+ "fen = '" + prob.fen + "'," +
+ "instruction = ?," +
+ "solution = ? " +
+ whereClause;
+ db.run(query, [prob.instruction, prob.solution]);
+ });
+ },
+
+ 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 " +
+ whereClause;
+ db.run(query);
+ });
+ },