<commit_before>/**
 * Created by MMo2 on 6/14/2016.
 */
'use strict';

let ObjectId = require('mongodb').ObjectId;
let DB = require('../helpers/dbHelper');

let COLLECTION = "chart_set_collection";
let CHART_SET_TYPE = "chartset";

DB.DATABASE_KEYS.push({
    COLLECTION: COLLECTION,
    keys: [{
        key: { friendlyUrl: 1 },
        option: { unique: true, sparse: true }
    }]
});

let getTimeStamp = () => new Date().valueOf();

exports.create = function(chartSetData, callback) {
    let db = DB.get();

    chartSetData.type = CHART_SET_TYPE;
    chartSetData.timestamp = getTimeStamp();
    chartSetData.lastUpdateTimestamp = chartSetData.timestamp;

    db.collection(COLLECTION).insert(chartSetData, function(err, result) {
        if (err) {
            return callback(err);
        }

        callback(null, result.ops[0]);
    });
};

exports.all = function(callback) {
    let db = DB.get();

    db.collection(COLLECTION).find().toArray(callback);
};

exports.getOne = function(_id, callback) {
    let db = DB.get();
    let regExp = /^s-/g;

    if (regExp.test(_id)) {
        db.collection(COLLECTION).find({ "friendlyUrl": _id }).toArray(callback);
    } else {
        db.collection(COLLECTION).find({ "_id": ObjectId(_id) }).toArray(callback);
    }
};

exports.clearCollection = function(callback) {
    let db = DB.get();

    db.collection(COLLECTION).remove({}, function(err, result) {
        callback(err);
    });
};

exports.remove = function(_id, callback) {
    let db = DB.get();

    db.collection(COLLECTION).removeOne({ _id: ObjectId(_id) }, function(err, result) {
        callback(err);
    });
};

exports.updateOne = function(_id, updateData, callback) {
    let db = DB.get();
    db.collection(COLLECTION).update({"_id":ObjectId(_id)}
        ,{
            "$set": {
                "title":updateData.title,
                "description":updateData.description,
                "friendlyUrl":updateData.friendlyUrl,
                "charts":updateData.charts,
                lastUpdateTimestamp: getTimeStamp()
            }
        }
        ,false,true, function(err, result) {
        callback(err);
    });
};<commit_msg>fixed updateChartSetById can't callback issue<commit_after>/**
 * Created by MMo2 on 6/14/2016.
 */
'use strict';

let ObjectId = require('mongodb').ObjectId;
let DB = require('../helpers/dbHelper');

let COLLECTION = "chart_set_collection";
let CHART_SET_TYPE = "chartset";

DB.DATABASE_KEYS.push({
    COLLECTION: COLLECTION,
    keys: [{
        key: { friendlyUrl: 1 },
        option: { unique: true, sparse: true }
    }]
});

let getTimeStamp = () => new Date().valueOf();

exports.create = function(chartSetData, callback) {
    let db = DB.get();

    chartSetData.type = CHART_SET_TYPE;
    chartSetData.timestamp = getTimeStamp();
    chartSetData.lastUpdateTimestamp = chartSetData.timestamp;

    db.collection(COLLECTION).insert(chartSetData, function(err, result) {
        if (err) {
            return callback(err);
        }

        callback(null, result.ops[0]);
    });
};

exports.all = function(callback) {
    let db = DB.get();

    db.collection(COLLECTION).find().toArray(callback);
};

exports.getOne = function(_id, callback) {
    let db = DB.get();
    let regExp = /^s-/g;

    if (regExp.test(_id)) {
        db.collection(COLLECTION).find({ "friendlyUrl": _id }).toArray(callback);
    } else {
        db.collection(COLLECTION).find({ "_id": ObjectId(_id) }).toArray(callback);
    }
};

exports.clearCollection = function(callback) {
    let db = DB.get();

    db.collection(COLLECTION).remove({}, function(err, result) {
        callback(err);
    });
};

exports.remove = function(_id, callback) {
    let db = DB.get();

    db.collection(COLLECTION).removeOne({ _id: ObjectId(_id) }, function(err, result) {
        callback(err);
    });
};

exports.updateOne = function(_id, updateData, callback) {
    let db = DB.get();
    db.collection(COLLECTION).update({"_id":ObjectId(_id)}
        ,{
            "$set": {
                "title":updateData.title,
                "description":updateData.description,
                "friendlyUrl":updateData.friendlyUrl,
                "charts":updateData.charts,
                lastUpdateTimestamp: getTimeStamp()
            }
        }
        ,false, function(err, result) {
        callback(err);
    });
};
{'fraction_non_alphanumeric': 0.15771428571428572, 'fraction_numerical': 0.004571428571428572, 'mean_word_length': 2.76268271711092, 'pattern_counts': {'":': 16, '<': 3, '<?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': '7428680', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1368, 'n_words': 250}