- if (!c.timeControl.match(/^[0-9dhms +]+$/))
- return "Wrong characters in time control";
-
- if (!c.fen.match(/^[a-zA-Z0-9, /-]+$/))
- return "Bad FEN string";
- },
-
- // fen cannot be undefined
- create: function(c, cb)
- {
- db.serialize(function() {
- let query =
- "INSERT INTO Challenges " +
- "(added, uid, " + (!!c.to ? "target, " : "") +
- "vid, fen, timeControl) VALUES " +
- "(" + Date.now() + "," + c.uid + "," + (!!c.to ? c.to + "," : "") +
- c.vid + ",'" + c.fen + "','" + c.timeControl + "')";
- db.run(query, err => {
- if (!!err)
- return cb(err);
- db.get("SELECT last_insert_rowid() AS rowid", (err2,lastId) => {
- return cb(err2, lastId);
- });
+ create: function(c, cb) {
+ db.serialize(function() {
+ const query =
+ "INSERT INTO Challenges " +
+ "(added, uid, " + (c.to ? "target, " : "") +
+ "vid, randomness, fen, cadence) " +
+ "VALUES " +
+ "(" + Date.now() + "," + c.uid + "," + (c.to ? c.to + "," : "") +
+ c.vid + "," + c.randomness + ",'" + c.fen + "','" + c.cadence + "')";
+ db.run(query, function(err) {
+ cb(err, { id: this.lastID });