<commit_before>'use strict';

const db = require('../../config/sequelize');
const StandardError = require('standard-error');

exports.all = function(req, res){
    db.post_travel_product.findAll({include: [{model:db.post_travel_product_document, attributes: ['image_name', 'image_path']}]}).then(
        function(product){
            return res.jsonp(product);
        }).catch(function(err){
            return res.jsonp(err);
        });
};

exports.show = function (req, res) {
    return res.jsonp(req.product);
};

exports.getPostTravelProductById = function (req, res, next, id) {
    db.post_travel_product.find({
        where: { id: id },
        include: [{
            model: db.post_travel_product_document
        }]
    }).then(function (product) {
        if (!product) {
            return next(new Error('Failed to load postTraveProductlId ' + id));
        } else {
            req.product = product;
            return next();
        }
    }).catch(function (err) {
        return next(err);
    });
};

exports.getPostTravelProductByProductCategoryId = function(req, res, next, id){
    db.post_travel_product.findAll({
        where: {product_category_id: id}

    }).then(function(product){
        req.product = product;
        return next();
        
    }).catch(function(err){
        return res.render('error', {
            error: err,
            status: 500
        })
    });
}

exports.getPostTravelByUserProfileId = function(req, res, next){
    db.post_travel.findAll({
        where: {profile_id: res.params.profileId},
        include: [{
            model: db.post_travel_product,
            include: [{
                model: db.post_travel_product_document
            }]
        }]

    }).then(function(travel){
        req.product = travel;
        return next();
        
    }).catch(function(err){
        return res.jsonp(err);
    });
}

exports.createProduct = function (req, res, next) {
    const msg = '';
    const product = {
        productName: req.body.productName,
        description: req.body.description,
        amount: req.body.amount
    }

    const productSave = db.post_travel_product.build(product);

    req.body.postProductId = productSave.id;

    productSave.save().then(function(){
        return next();
    }).catch(function(err){<commit_msg>Cannot to have duplicate api name<commit_after>'use strict';

const db = require('../../config/sequelize');
const StandardError = require('standard-error');

exports.all = function(req, res){
    db.post_travel_product.findAll({include: [{model:db.post_travel_product_document, attributes: ['image_name', 'image_path']}]}).then(
        function(product){
            return res.jsonp(product);
        }).catch(function(err){
            return res.jsonp(err);
        });
};

exports.show = function (req, res) {
    return res.jsonp(req.product);
};

exports.getPostTravelProductById = function (req, res, next, id) {
    db.post_travel_product.find({
        where: { id: id },
        include: [{
            model: db.post_travel_product_document
        }]
    }).then(function (product) {
        if (!product) {
            return next(new Error('Failed to load postTraveProductlId ' + id));
        } else {
            req.product = product;
            return next();
        }
    }).catch(function (err) {
        return next(err);
    });
};

exports.getPostTravelProductByProductCategoryId = function(req, res, next, id){
    db.post_travel_product.findAll({
        where: {product_category_id: id}

    }).then(function(product){
        req.product = product;
        return next();
        
    }).catch(function(err){
        return res.render('error', {
            error: err,
            status: 500
        })
    });
}

exports.getPostTravelByUserProfileId = function(req, res, next){
    db.post_travel.findAll({
        where: {profile_id: req.params.userProfileId},
        include: [{
            model: db.post_travel_product,
            include: [{
                model: db.post_travel_product_document
            }]
        }]

    }).then(function(travel){
        req.product = travel;
        return next();
        
    }).catch(function(err){
        return res.jsonp(err);
    });
}

exports.createProduct = function (req, res, next) {
    const msg = '';
    const product = {
        productName: req.body.productName,
        description: req.body.description,
        amount: req.body.amount
    }

    const productSave = db.post_travel_product.build(product);

    req.body.postProductId = productSave.id;

    productSave.save().then(function(){
        return next();
    }).catch(function(err){
{'fraction_non_alphanumeric': 0.1393056150878697, 'fraction_numerical': 0.0012858979854264896, 'mean_word_length': 2.338340486409156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4144325', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1346, 'n_words': 260}