docparse-upload-process
Version:
process upload api request for the docparse server
40 lines (38 loc) • 1.27 kB
JavaScript
var inspect = require('eyespect').inspector();
var should = require('should');
var User = require('docparse-user');
module.exports = function(data, cb) {
if (!cb) {
cb = data;
data = {
username: 'username1',
password: 'password1',
email: 'test@example.com'
}
}
User.findOne({username: data.username}, function (err, reply) {
if (err) { return cb(err); }
if (reply) {
return cb(null, reply);
}
User.register(data, function (err, reply) {
should.not.exist(err, 'error registering reply: ' + err);
should.exist(reply, 'no reply document returned from register function');
reply.should.not.have.property('password');
reply.username.should.eql(data.username);
User.findOne({username: data.username}, function (err, user) {
if (err) { return cb(err); }
user.api = true;
user.confirmed = true;
user.save(function(err) {
should.not.exist(err);
User.findOne({username: data.username}, function (err, reply) {
should.not.exist(err, 'error looking up user by username: ' + err);
should.exist(reply, 'failed to find user by username');
cb(null, reply);
});
});
});
});
});
}