Skip to content

Commit

Permalink
chore(code): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Mar 21, 2019
1 parent fb0face commit d119211
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 82 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trudesk",
"version": "1.0.9",
"version": "1.0.10-beta",
"private": true,
"engines": {
"node": ">=9.10.0"
Expand Down
81 changes: 0 additions & 81 deletions src/controllers/api/v1/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,87 +18,6 @@ var winston = require('winston')

var commonV1 = {}

commonV1.import = function (req, res) {
var fs = require('fs')
var path = require('path')
var UserModal = require('../../../models/user')
var groupModel = require('../../../models/group')

var array = fs
.readFileSync(path.join(__dirname, '..', 'import.csv'))
.toString()
.split('\n')
var clean = array.filter(function (e) {
return e
})

async.eachSeries(
clean,
function (item, cb) {
winston.info(item)

var fields = item.split(',')
var fullname = fields[0].toString().replace('.', ' ')
var k = fullname.split(' ')
var kCap = _.capitalize(k[0])
var kCap1 = _.capitalize(k[1])
fullname = kCap + ' ' + kCap1

var groupName = fields[2].replace('\\r', '')
groupName = _.trim(groupName)
var User = new UserModal({
username: fields[0],
password: 'Password123',
email: fields[1],
fullname: fullname,
role: 'user'
})

async.series(
[
function (next) {
User.save(function (err) {
if (err) return next(err)

next()
})
},
function (next) {
winston.debug('Getting Group "' + groupName + '"')
groupModel.getGroupByName(groupName, function (err, group) {
if (err) return next(err)

if (_.isUndefined(group) || _.isNull(group)) {
return next('no group found = ' + groupName)
}

group.addMember(User._id, function (err) {
if (err) return next(err)

group.save(function (err) {
if (err) return next(err)

next()
})
})
})
}
],
function (err) {
if (err) return cb(err)

cb()
}
)
},
function (err) {
if (err) return res.status(500).send(err)

res.status(200).send('Imported ' + _.size(clean))
}
)
}

/**
* Preforms login with username/password and adds
* an access token to the {@link User} object.
Expand Down

0 comments on commit d119211

Please sign in to comment.