commands/end.js
/**
         * @brief This function is invoked when the database lookup operation to
         *        find the channel's ongoing game is complete. If a valid game
         *        is found, its state in the database is updated.
         *
         * @param error db lookup error
         * @param game valid game from the db
         *
         * @return none
         */
@brief This function is invoked when the database lookup operation to
find the channel's ongoing game is complete. If a valid game
is found, its state in the database is updated.

@param error db lookup error
@param game valid game from the db

@return none
@brief This function is invoked when the database lookup operation to find the channel ' s ongoing game is complete . If a valid game is found its state in the database is updated . @param error db lookup error @param game valid game from the db @return none
function dbLookupCallback(error, game) {
            if (error !== undefined && error !== null) {
                logger.error(error);
                return res.json(
                    slackUtil.createResponse({
                        text: labels.DB_ERROR,
                        response_type: "ephemeral"
                    })
                );
            }
            if (game === undefined || game === null) {
                return res.json(
                    slackUtil.createResponse({
                        text: labels.GAME_NOT_FOUND_ERROR,
                        response_type: "ephemeral"
                    })
                );
            }
            let players = game.players;
            if (players[0].name !== player && players[1].name !== player) {
                return res.json(
                    slackUtil.createResponse({
                        text: labels.CMD_ERROR,
                        response_type: "ephemeral",
                        attachments: [{
                            text: util.format(
                                labels.CMD_DETAIL_ERROR,
                                slackUtil.getUserDisplay(players[0]),
                                slackUtil.getUserDisplay(players[1])
                            ),
                            color: "#ff0000",
                            mrkdwn_in: [
                                "text"
                            ]
                        }]
                    })
                );
            }
            game.state = constants.gameState.NORESULT;
            db.update(game, function (error) {
                if (error) {
                    return res.send(error);
                }
                res.json(
                    slackUtil.createResponse({
                        text: util.format(
                            labels.CMD_SUCCESS,
                            slackUtil.getUserDisplay(players[0]),
                            slackUtil.getUserDisplay(players[1])
                        )
                    })
                );
            });
        }
function dbLookupCallback ( error , game ) { if ( error !== undefined && error !== null ) { logger . error ( error ) ; return res . json ( slackUtil . createResponse ( { text : labels . DB_ERROR , response_type : "ephemeral" } ) ) ; } if ( game === undefined || game === null ) { return res . json ( slackUtil . createResponse ( { text : labels . GAME_NOT_FOUND_ERROR , response_type : "ephemeral" } ) ) ; } let players = game . players ; if ( players [ 0 ] . name !== player && players [ 1 ] . name !== player ) { return res . json ( slackUtil . createResponse ( { text : labels . CMD_ERROR , response_type : "ephemeral" , attachments : [ { text : util . format ( labels . CMD_DETAIL_ERROR , slackUtil . getUserDisplay ( players [ 0 ] ) , slackUtil . getUserDisplay ( players [ 1 ] ) ) , color : "#ff0000" , mrkdwn_in : [ "text" ] } ] } ) ) ; } game . state = constants . gameState . NORESULT ; db . update ( game , function ( error ) { if ( error ) { return res . send ( error ) ; } res . json ( slackUtil . createResponse ( { text : util . format ( labels . CMD_SUCCESS , slackUtil . getUserDisplay ( players [ 0 ] ) , slackUtil . getUserDisplay ( players [ 1 ] ) ) } ) ) ; } ) ; }
@brief This function is invoked when the database lookup operation to
        find the channel's ongoing game is complete.
@brief This function is invoked when the database lookup operation to find the channel ' s ongoing game is complete .
// No ongling game found in this channel. // No ongling game found in this channel. // Check if the user running this command is one of the 2 players. // End the game by updating the game state. // Save the upated record to the database