/////////////////////////
// Gets an event price //
/////////////////////////

'use strict';

module.exports = function (db, config) {
    return function (req, res) {
        var logger = require('../../lib/log')(config);
        var rest   = require('../../lib/rest')(config, logger);

        var eid = req.params.eventId;
        // If an user is connected
        if (req.user) {
            // If he's in bde
            if (req.user.inBDE) {
                db.Price.find({
                    where: {
                        event_id: eid,
                        name: { like: '%cotisant en prévente' }
                    }
                }).complete(treatPrice);
            } else {
                db.Price.find({
                    where: {
                        event_id: eid,
                        name: { like: '%non-cotisant en prévente' }
                    }
                }).complete(treatPrice);
            }
        } else {
            var mail = (req.query.mail === 'undefined') ? undefined : req.query.mail;
            db.SchoolDomain.findAll().complete(function (err, domains) {
                if (err) {
                    return Error.emit(res, 500, '500 - SQL Server error', err);
                }

                var partnerPrice = false;
                domains.forEach(function (domain) {
                    var reg = new RegExp('@' + domain.domain + '$', 'i');
                    if (reg.test(mail)) {
                        partnerPrice = true;
                    }
                });

                if (partnerPrice) {
                    db.Price.find({
                        where: {
                            event_id: eid,
                            name: { like: '%partenaire en prévente' }
                        }
                    }).complete(treatPrice);
                } else {
                    db.Price.find({
                        where: {
                            event_id: eid,
                            name: { like: '%extérieur en prévente' }
                        }
                    }).complete(treatPrice);
                }
            });
            return;
        }

        function treatPrice (err, price) {
            if (err) {
                return Error.emit(res, 500, '500 - SQL Server error', err);
            }

            if (!price) {
                return res.status(404).end();
            }

            var priceValue = price.price || price.dataValues.price;
            res.status(200).end(priceValue.toString());
        }
    };
};

@@ -1807,34 +1807,732 @@
 %7D).complete(
-treatPrice
+function (err, price) %7B%0A                        if (err) %7B%0A                            return Error.emit(res, 500, '500 - SQL Server error', err);%0A                        %7D%0A%0A                        if (!price) %7B%0A                            db.Price.find(%7B%0A                                where: %7B%0A                                    event_id: eid,%0A                                    name: %7B like: '%25ext%C3%A9rieur en pr%C3%A9vente' %7D%0A                                %7D%0A                            %7D).complete(treatPrice);%0A                        %7D%0A%0A                        var priceValue = price.price %7C%7C price.dataValues.price;%0A                        res.status(200).end(priceValue.toString());%0A                    %7D
 );%0A         

Fix price when ext and no partner prices. If the client puts his partner email, should validate with ext price