'use strict';

var q = require("q");
var lodashLang = require('lodash/lang');
var logger = require('../../utils/Logger').loggers.get('db');


module.exports.preProcess = function(field, document){
    var deferred = q.defer();

    if(document[field.name]) {
        if (lodashLang.isString(document[field.name])) {
//            if (lodashLang.isEmpty(document[field.name])) {
//                delete document[field.name];
//            }
            deferred.resolve(document);
        }else{
            var errMsg = field.componentName + " field named " + field.name + " has invalid value";
            deferred.reject(errMsg);
        }
    }else{
        deferred.resolve(document);
    }

    return deferred.promise;
};