Ejemplo n.º 1
0
        return getGameVersion(gameId, versionId).then(function (result) {
            return sessions.getActiveSession(result.game._id, result.version._id).then(function (session) {
                if (session) {
                    throw {
                        message: 'A session for this version already exists',
                        status: 400
                    }
                }

                return sessions.insert({
                    gameId: result.game._id,
                    gameId: result.version._id,
                    start: new Date(),
                    end: null
                }).then(function (session) {
                    return startSessionAnalysis(session._id)
                        .then(function () {
                            return session;
                        }).fail(function (err) {
                            return sessions.removeById(session._id).then(function () {
                                throw err;
                            });
                        });
                });
            });
        });
Ejemplo n.º 2
0
    sessions.endSession = function (gameId, versionId) {
        gameId = sessions.toObjectID(gameId);
        versionId = sessions.toObjectID(versionId);
        return sessions.getActiveSession(gameId, versionId).then(function (session) {
            if (!session) {
                throw {
                    message: 'Session does not exist',
                    status: 400
                }
            }

            return sessions.findAndModify(session._id, {end: new Date()})
                .then(function (session) {
                    return endSessionAnalysis(session._id).then(function () {
                        return session;
                    });
                });
        });
    };