projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some fixes, working on corr challenges
[vchess.git]
/
server
/
models
/
Game.js
diff --git
a/server/models/Game.js
b/server/models/Game.js
index
6f15137
..
954ffc4
100644
(file)
--- a/
server/models/Game.js
+++ b/
server/models/Game.js
@@
-6,8
+6,7
@@
var db = require("../utils/database");
* vid: integer (variant id)
* fenStart: varchar (initial position)
* fen: varchar (current position)
* vid: integer (variant id)
* fenStart: varchar (initial position)
* fen: varchar (current position)
- * mainTime: integer
- * addTime: integer (increment)
+ * timeControl: string
* score: varchar (result)
*
* Structure table Players:
* score: varchar (result)
*
* Structure table Players:
@@
-27,13
+26,12
@@
var db = require("../utils/database");
const GameModel =
{
const GameModel =
{
- // mainTime and increment in milliseconds
- create: function(vid, fen, mainTime, increment, players, cb)
+ create: function(vid, fen, timeControl, players, cb)
{
{
- db.serialize({
+ db.serialize(
function()
{
let query =
let query =
- "INSERT INTO Games (vid, fen,
mainTime, addTime
) " +
- "VALUES (" + vid + ",'" + fen + "'," +
mainTime + "," + increment
+ ")";
+ "INSERT INTO Games (vid, fen,
timeControl
) " +
+ "VALUES (" + vid + ",'" + fen + "'," +
timeControl
+ ")";
db.run(insertQuery, err => {
if (!!err)
return cb(err);
db.run(insertQuery, err => {
if (!!err)
return cb(err);
@@
-41,7
+39,8
@@
const GameModel =
players.forEach(p => {
query =
"INSERT INTO Players VALUES " +
players.forEach(p => {
query =
"INSERT INTO Players VALUES " +
- "(" + lastId["rowid"] + "," + p.id + "," + p.color + "," + mainTime + ")";
+ // Remaining time = -1 means "unstarted"
+ "(" + lastId["rowid"] + "," + p.id + "," + p.color + ", -1)";
db.run(query, cb);
});
});
db.run(query, cb);
});
});
@@
-105,6
+104,7
@@
const GameModel =
db.run(query, (err,gameIds) => {
if (!!err)
return cb(err);
db.run(query, (err,gameIds) => {
if (!!err)
return cb(err);
+ gameIds = gameIds || []; //might be empty
let gameArray = [];
gameIds.forEach(gidRow => {
GameModel.getOne(gidRow["gid"], (err2,game) => {
let gameArray = [];
gameIds.forEach(gidRow => {
GameModel.getOne(gidRow["gid"], (err2,game) => {