- fen: req.body.chall.fen,
- cadence: req.body.chall.cadence,
- vid: req.body.chall.vid,
- uid: req.userId,
- to: req.body.chall.to, //string: user name (may be empty)
- };
- const insertChallenge = () => {
- ChallengeModel.create(challenge, (err,ret) => {
- return res.json(err || {cid:ret.cid});
- });
- };
- if (!!req.body.chall.to)
- {
- UserModel.getOne("name", challenge.to, (err,user) => {
- if (!!err || !user)
- return res.json(err || {errmsg: "Typo in player name"});
- challenge.to = user.id; //ready now to insert challenge
+ let challenge =
+ {
+ fen: req.body.chall.fen,
+ cadence: req.body.chall.cadence,
+ vid: req.body.chall.vid,
+ uid: req.userId,
+ to: req.body.chall.to, //string: user name (may be empty)
+ };
+ const insertChallenge = () => {
+ ChallengeModel.create(challenge, (err,ret) => {
+ res.json(err || {cid:ret.cid});
+ });
+ };
+ if (req.body.chall.to)
+ {
+ UserModel.getOne("name", challenge.to, (err,user) => {
+ if (!!err || !user)
+ res.json(err || {errmsg: "Typo in player name"});
+ else
+ {
+ challenge.to = user.id; //ready now to insert challenge
+ insertChallenge();
+ if (user.notify)
+ UserModel.notify(
+ user,
+ "New challenge: " + params.siteURL + "/#/?disp=corr");
+ }
+ });
+ }
+ else