- ChallengeModel.create(challenge, (err,lastId) => {
- if (!!err)
- return res.json(err);
- if (!!req.body.chall.to[0])
- {
- UserModel.getByName(req.body.chall.to, (err,users) => {
- if (!!err)
- return res.json(err);
- if (users.length < req.body.chall.to.length)
- return res.json({errmsg: "Typo in player(s) name(s)"});
- ChallengeModel.initializeWillPlay(
- users.map(u => u.id),
- lastId["rowid"],
- (err) => {
- if (!!err)
- return res.json(err);
- res.json({cid: lastId["rowid"]});
- }
- );
- });
- }
- else
- res.json({cid: lastId["rowid"]});
- });
-});
-
-// Nothing to do if challenge is refused (just removal)
-router.put("/challenges", access.logged, access.ajax, (req,res) => {
- switch (req.body.action)
+ const insertChallenge = () => {
+ ChallengeModel.create(challenge, (err) => {
+ if (!!err)
+ return res.json(err);
+ });
+ };
+ if (!!req.body.chall.to)