<commit_before>var service = require('../service/service');
var moment = require('moment');

function sendErr(res, message) {
    res.send({
        success: false,
        message: message
    });
}
// service.user.setInfo(1448263981073,'name','starkwang').then(function(result){
//     console.log('success');
// },function(err){
//     console.log(err);
// });
var item = {
    // '/api/item/collection' GET
    collection: function(req, res) {
        service.item.collection(req.query)
            .then(function(results) {
                var items = [];
                for (var i = 0; i < results.length; i++) {
                    var object = results[i];
                    items.push({
                        image: object.get('imgPaths'),
                        price: object.get('price'),
                        name: object.get('name'),
                        location: object.get('location'),
                        publisher_id: object.get('publisher_id'),
                        publisher_name: object.get('publisher_name'),
                        pubTimeStamp: object.get('pubTimeStamp'),
                        pubTime: moment(parseInt(object.get('pubTimeStamp'))).fromNow()
                    })
                }
                res.send(items);
                res.end();
            }, function(err) {
                sendErr(res, err);
            });
    },

    // '/api/item/publish' POST
    publish: function(req, res) {
        if (req.session.login && req.session.emailVerified && req.body.name && req.body.detail && req.body.price && req.body.tel && req.body.category && req.body.imgPaths.length > 0) {
            req.body.publisher_id = req.session.userid;
            req.body.publisher_name = req.session.name
            service.item.publish(req.body)
                .then(function(result) {
                    console.log(result);
                    res.send({
                        success: true,
                        //id: result.id
                    })
                }, function(err) {
                    sendErr(res, err);;
                });
        } else {
            sendErr(res, 'params error');
        }

    },
    // '/api/item/get/' GET
    get: function(req, res) {<commit_msg>修复发布的bug<commit_after>var service = require('../service/service');
var moment = require('moment');

function sendErr(res, message) {
    res.send({
        success: false,
        message: message
    });
}
// service.user.setInfo(1448263981073,'name','starkwang').then(function(result){
//     console.log('success');
// },function(err){
//     console.log(err);
// });
var item = {
    // '/api/item/collection' GET
    collection: function(req, res) {
        service.item.collection(req.query)
            .then(function(results) {
                var items = [];
                for (var i = 0; i < results.length; i++) {
                    var object = results[i];
                    items.push({
                        image: object.get('imgPaths'),
                        price: object.get('price'),
                        name: object.get('name'),
                        location: object.get('location'),
                        publisher_id: object.get('publisher_id'),
                        publisher_name: object.get('publisher_name'),
                        pubTimeStamp: object.get('pubTimeStamp'),
                        pubTime: moment(parseInt(object.get('pubTimeStamp'))).fromNow()
                    })
                }
                res.send(items);
                res.end();
            }, function(err) {
                sendErr(res, err);
            });
    },

    // '/api/item/publish' POST
    publish: function(req, res) {
        if (req.session.login && req.session.emailVerified && req.body.name && req.body.detail && req.body.price && (req.body.tel || req.body.wechat || req.body.qq) && req.body.category && req.body.imgPaths.length > 0) {
            req.body.publisher_id = req.session.userid;
            req.body.publisher_name = req.session.name
            service.item.publish(req.body)
                .then(function(result) {
                    console.log(result);
                    res.send({
                        success: true,
                        //id: result.id
                    })
                }, function(err) {
                    sendErr(res, err);;
                });
        } else {
            sendErr(res, 'params error');
        }

    },
    // '/api/item/get/' GET
    get: function(req, res) {
{'fraction_non_alphanumeric': 0.14666373045584674, 'fraction_numerical': 0.006606474344857961, 'mean_word_length': 1.3917851500789888, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2304198', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1207, 'n_words': 202}