'use strict';

var _ = require('lodash');

var Users = require('../lib/dbModels/Users');

var UsersModel = function UsersModelConstructor() {
    return {
        get: function(name, cb) {
            var found;

            if (_.isUndefined(cb) && _.isFunction(name)) {
                cb = name;
                name = null;
            }

            if (_.isNull(name)) {
                found = Users.all();
            }
            else {
                found = Users.findOne({ where: { name: name } });
            }

            return found
                .then(function (result) {
                    cb(null, result);
                })
                .catch(function (err) {
                    cb(err);
                });
        },
        post: function(user, cb) {
            return Users.create(user)
                .then(function(result) {
                    cb(null, result);
                })
                .catch(function (err) {
                    cb(err);
                });
        }
    };
};

module.exports = UsersModel();

@@ -34,16 +34,45 @@
 odash');
+%0Avar B = require('bluebird');
 %0A%0Avar Us
@@ -825,33 +825,432 @@
     
-return Users.create(user)
+var promises = %5B%5D;%0A            var fulfilledPromise;%0A%0A            if (_.isArray(user)) %7B%0A                _.forEach(user, function(v) %7B%0A                    promises.push(Users.create(v));%0A                %7D);%0A                fulfilledPromise = B.all(promises);%0A            %7D%0A            else if (_.isPlainObject(user)) %7B%0A                fulfilledPromise = Users.create(user);%0A            %7D%0A%0A            return fulfilledPromise
 %0A   

allow passing array of users to create