X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fmodels%2FChallenge.js;h=f82f9e817938c4bf51f80a2150a6564d53a8e499;hb=8c564f462f5406fcd311d4733f851daf6ada665d;hp=82b252fd281bf6b59cb3b8aa19bcb4606dc0719e;hpb=bebcc8d45532e67902175f69084a08040f06855f;p=vchess.git diff --git a/server/models/Challenge.js b/server/models/Challenge.js index 82b252fd..f82f9e81 100644 --- a/server/models/Challenge.js +++ b/server/models/Challenge.js @@ -34,8 +34,8 @@ const ChallengeModel = "vid, fen, timeControl) VALUES " + "(" + Date.now() + "," + c.uid + "," + (!!c.to ? c.to + "," : "") + c.vid + ",'" + c.fen + "','" + c.timeControl + "')"; - db.run(query, err => { - return cb(err); + db.run(query, function(err) { + return cb(err, {cid: this.lastID}); }); }); }, @@ -67,20 +67,27 @@ const ChallengeModel = }); }, - remove: function(id, uid, cb) + remove: function(id) { db.serialize(function() { - let query = + const query = + "DELETE FROM Challenges " + + "WHERE id = " + id; + db.run(query); + }); + }, + + safeRemove: function(id, uid, cb) + { + db.serialize(function() { + const query = "SELECT 1 " + "FROM Challenges " + "WHERE id = " + id + " AND uid = " + uid; db.get(query, (err,chall) => { if (!chall) return cb({errmsg: "Not your challenge"}); - query = - "DELETE FROM Challenges " + - "WHERE id = " + id; - db.run(query); + ChallengeModel.remove(id); cb(null); }); });