- getOne: function(id, cb)
- {
- db.serialize(function() {
- let query =
- "SELECT * " +
- "FROM Challenges " +
- "WHERE id = " + id;
- db.get(query, (err,challengeInfo) => {
- if (!!err)
- return cb(err);
- let condition = "";
- if (!!challengeInfo.to)
- condition = "IN (" + challengeInfo.uid + "," + challengeInfo.to + ")";
- else
- condition = "= " + challengeInfo.uid;
- query =
- "SELECT id, name " +
- "FROM Users " +
- "WHERE id " + condition;
- db.run(query, (err2,players) => {
- if (!!err2)
- return cb(err2);
- const challenge = {
- id: id,
- uid: challengeInfo.uid, //sender (but we don't know who ask)
- vid: challengeInfo.vid,
- added: challengeInfo.added,
- players: players, //sender + potential receiver
- fen: challengeInfo.fen,
- timeControl: challengeInfo.timeControl,
- };
- return cb(null, challenge);
- });
- });
- });
- },
+ getOne: function(id, cb)
+ {
+ db.serialize(function() {
+ let query =
+ "SELECT * " +
+ "FROM Challenges " +
+ "WHERE id = " + id;
+ db.get(query, (err,challenge) => {
+ return cb(err, challenge);
+ });
+ });
+ },