ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [21/29] ignite git commit: IGNITE-843 Fixed eslint warnings.
Date Fri, 12 Feb 2016 09:54:47 GMT
IGNITE-843 Fixed eslint warnings.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/33061ca9
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/33061ca9
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/33061ca9

Branch: refs/heads/ignite-843-rc3
Commit: 33061ca97f322abe0907cb6fbb885c5c06e24d9b
Parents: da47087
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Fri Feb 12 16:15:56 2016 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Fri Feb 12 16:15:56 2016 +0700

----------------------------------------------------------------------
 .../src/main/js/serve/routes/caches.js          | 112 ++++++-----
 .../src/main/js/serve/routes/clusters.js        | 131 ++++++------
 .../src/main/js/serve/routes/domains.js         | 200 +++++++++----------
 3 files changed, 219 insertions(+), 224 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/33061ca9/modules/control-center-web/src/main/js/serve/routes/caches.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/caches.js b/modules/control-center-web/src/main/js/serve/routes/caches.js
index bb7097a..be29633 100644
--- a/modules/control-center-web/src/main/js/serve/routes/caches.js
+++ b/modules/control-center-web/src/main/js/serve/routes/caches.js
@@ -34,56 +34,54 @@ module.exports.factory = function(_, express, mongo) {
          * @param req Request.
          * @param res Response.
          */
-        router.post('/list', function(req, res) {
+        router.post('/list', (req, res) => {
             const user_id = req.currentUserId();
 
             // Get owned space and all accessed space.
-            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
function(errSpace, spaces) {
+            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
(errSpace, spaces) => {
                 if (mongo.processed(errSpace, res)) {
-                    const space_ids = spaces.map(function(value) {
-                        return value._id;
-                    });
+                    const space_ids = spaces.map((value) => value._id);
 
                     // Get all clusters for spaces.
-                    mongo.Cluster.find({space: {$in: space_ids}}, '_id name caches').sort('name').exec(function(errCluster,
clusters) {
+                    mongo.Cluster.find({space: {$in: space_ids}}, '_id name caches').sort('name').exec((errCluster,
clusters) => {
                         if (mongo.processed(errCluster, res)) {
                             // Get all domain models for spaces.
-                            mongo.DomainModel.find({space: {$in: space_ids}}).sort('name').exec(function(errDomainModel,
domains) {
+                            mongo.DomainModel.find({space: {$in: space_ids}}).sort('name').exec((errDomainModel,
domains) => {
                                 if (mongo.processed(errDomainModel, res)) {
                                     // Get all caches for spaces.
-                                    mongo.Cache.find({space: {$in: space_ids}}).sort('name').exec(function(err,
caches) {
+                                    mongo.Cache.find({space: {$in: space_ids}}).sort('name').exec((err,
caches) => {
                                         if (mongo.processed(err, res)) {
-                                            _.forEach(clusters, function(cluster) {
-                                                cluster.caches = _.filter(cluster.caches,
function(cacheId) {
+                                            _.forEach(clusters, (cluster) => {
+                                                cluster.caches = _.filter(cluster.caches,
(cacheId) => {
                                                     return _.find(caches, {_id: cacheId});
                                                 });
                                             });
 
-                                            _.forEach(domains, function(domain) {
-                                                domain.caches = _.filter(domain.caches, function(cacheId)
{
+                                            _.forEach(domains, (domain) => {
+                                                domain.caches = _.filter(domain.caches, (cacheId)
=> {
                                                     return _.find(caches, {_id: cacheId});
                                                 });
                                             });
 
-                                            _.forEach(caches, function(cache) {
+                                            _.forEach(caches, (cache) => {
                                                 // Remove deleted clusters.
-                                                cache.clusters = _.filter(cache.clusters,
function(clusterId) {
-                                                    return _.findIndex(clusters, function(cluster)
{
+                                                cache.clusters = _.filter(cache.clusters,
(clusterId) => {
+                                                    return _.findIndex(clusters, (cluster)
=> {
                                                         return cluster._id.equals(clusterId);
                                                     }) >= 0;
                                                 });
 
                                                 // Remove deleted domain models.
-                                                cache.domains = _.filter(cache.domains, function(metaId)
{
-                                                    return _.findIndex(domains, function(domain)
{
+                                                cache.domains = _.filter(cache.domains, (metaId)
=> {
+                                                    return _.findIndex(domains, (domain)
=> {
                                                         return domain._id.equals(metaId);
                                                     }) >= 0;
                                                 });
                                             });
 
                                             res.json({
-                                                spaces: spaces,
-                                                clusters: clusters.map(function(cluster)
{
+                                                spaces,
+                                                clusters: clusters.map((cluster) => {
                                                     return {
                                                         value: cluster._id,
                                                         label: cluster.name,
@@ -106,25 +104,26 @@ module.exports.factory = function(_, express, mongo) {
         /**
          * Save cache.
          */
-        router.post('/save', function(req, res) {
+        router.post('/save', (req, res) => {
             const params = req.body;
             const clusters = params.clusters;
             const domains = params.domains;
             let cacheId = params._id;
 
             if (params._id) {
-                mongo.Cache.update({_id: cacheId}, params, {upsert: true}, function(err)
{
-                    if (mongo.processed(err, res)) {
-                        mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet: {caches:
cacheId}}, {multi: true}, function (err) {
-                            if (mongo.processed(err, res)) {
-                                mongo.Cluster.update({_id: {$nin: clusters}}, {$pull: {caches:
cacheId}}, {multi: true}, function (err) {
-                                    if (mongo.processed(err, res)) {
-                                        mongo.DomainModel.update({_id: {$in: domains}}, {$addToSet:
{caches: cacheId}}, {multi: true}, function (err) {
-                                            if (mongo.processed(err, res))
-                                                mongo.DomainModel.update({_id: {$nin: domains}},
{$pull: {caches: cacheId}}, {multi: true}, function (err) {
-                                                    if (mongo.processed(err, res))
+                mongo.Cache.update({_id: cacheId}, params, {upsert: true}, (errCache) =>
{
+                    if (mongo.processed(errCache, res)) {
+                        mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet: {caches:
cacheId}}, {multi: true}, (errClusterAdd) => {
+                            if (mongo.processed(errClusterAdd, res)) {
+                                mongo.Cluster.update({_id: {$nin: clusters}}, {$pull: {caches:
cacheId}}, {multi: true}, (errClusterPull) => {
+                                    if (mongo.processed(errClusterPull, res)) {
+                                        mongo.DomainModel.update({_id: {$in: domains}}, {$addToSet:
{caches: cacheId}}, {multi: true}, (errDomainModelAdd) => {
+                                            if (mongo.processed(errDomainModelAdd, res))
{
+                                                mongo.DomainModel.update({_id: {$nin: domains}},
{$pull: {caches: cacheId}}, {multi: true}, (errDomainModelPull) => {
+                                                    if (mongo.processed(errDomainModelPull,
res))
                                                         res.send(params._id);
                                                 });
+                                            }
                                         });
                                     }
                                 });
@@ -133,34 +132,36 @@ module.exports.factory = function(_, express, mongo) {
                     }
                 });
             }
-            else
-                mongo.Cache.findOne({space: params.space, name: params.name}, function(err,
cache) {
-                    if (mongo.processed(err, res)) {
-                        if (cache)
-                            return res.status(500).send('Cache with name: "' + cache.name
+ '" already exist.');
-
-                        (new mongo.Cache(params)).save(function(err, cache) {
-                            if (mongo.processed(err, res)) {
+            else {
+                mongo.Cache.findOne({space: params.space, name: params.name}, (errCacheFind,
cacheFound) => {
+                    if (mongo.processed(errCacheFind, res)) {
+                        if (cacheFound)
+                            return res.status(500).send('Cache with name: "' + cacheFound.name
+ '" already exist.');
+
+                        (new mongo.Cache(params)).save((errCacheSave, cache) => {
+                            if (mongo.processed(errCacheSave, res)) {
                                 cacheId = cache._id;
 
-                                mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet:
{caches: cacheId}}, {multi: true}, function(err) {
-                                    if (mongo.processed(err, res))
-                                        mongo.DomainModel.update({_id: {$in: domains}}, {$addToSet:
{caches: cacheId}}, {multi: true}, function(err) {
-                                            if (mongo.processed(err, res))
+                                mongo.Cluster.update({_id: {$in: clusters}}, {$addToSet:
{caches: cacheId}}, {multi: true}, (errCluster) => {
+                                    if (mongo.processed(errCluster, res)) {
+                                        mongo.DomainModel.update({_id: {$in: domains}}, {$addToSet:
{caches: cacheId}}, {multi: true}, (errDomainModel) => {
+                                            if (mongo.processed(errDomainModel, res))
                                                 res.send(cacheId);
                                         });
+                                    }
                                 });
                             }
                         });
                     }
                 });
+            }
         });
 
         /**
          * Remove cache by ._id.
          */
-        router.post('/remove', function(req, res) {
-            mongo.Cache.remove(req.body, function(err) {
+        router.post('/remove', (req, res) => {
+            mongo.Cache.remove(req.body, (err) => {
                 if (mongo.processed(err, res))
                     res.sendStatus(200);
             });
@@ -169,26 +170,27 @@ module.exports.factory = function(_, express, mongo) {
         /**
          * Remove all caches.
          */
-        router.post('/remove/all', function(req, res) {
+        router.post('/remove/all', (req, res) => {
             const user_id = req.currentUserId();
 
             // Get owned space and all accessed space.
-            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
function(err, spaces) {
-                if (mongo.processed(err, res)) {
-                    const space_ids = spaces.map(function(value) {
+            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
(errSpace, spaces) => {
+                if (mongo.processed(errSpace, res)) {
+                    const space_ids = spaces.map((value) => {
                         return value._id;
                     });
 
-                    mongo.Cache.remove({space: {$in: space_ids}}, function(err) {
-                        if (err)
-                            return res.status(500).send(err.message);
+                    mongo.Cache.remove({space: {$in: space_ids}}, (errCache) => {
+                        if (errCache)
+                            return res.status(500).send(errCache.message);
 
-                        mongo.Cluster.update({space: {$in: space_ids}}, {caches: []}, {multi:
true}, function(err) {
-                            if (mongo.processed(err, res))
-                                mongo.DomainModel.update({space: {$in: space_ids}}, {caches:
[]}, {multi: true}, function(err) {
-                                    if (mongo.processed(err, res))
+                        mongo.Cluster.update({space: {$in: space_ids}}, {caches: []}, {multi:
true}, (errCluster) => {
+                            if (mongo.processed(errCluster, res)) {
+                                mongo.DomainModel.update({space: {$in: space_ids}}, {caches:
[]}, {multi: true}, (errDomainModel) => {
+                                    if (mongo.processed(errDomainModel, res))
                                         res.sendStatus(200);
                                 });
+                            }
                         });
                     });
                 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/33061ca9/modules/control-center-web/src/main/js/serve/routes/clusters.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/clusters.js b/modules/control-center-web/src/main/js/serve/routes/clusters.js
index 4c5a92e..0ca2fed 100644
--- a/modules/control-center-web/src/main/js/serve/routes/clusters.js
+++ b/modules/control-center-web/src/main/js/serve/routes/clusters.js
@@ -32,61 +32,55 @@ module.exports.factory = function(_, express, mongo) {
          * @param req Request.
          * @param res Response.
          */
-        router.post('/list', function(req, res) {
-            var user_id = req.currentUserId();
+        router.post('/list', (req, res) => {
+            const user_id = req.currentUserId();
 
             // Get owned space and all accessed space.
-            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
function(err, spaces) {
-                if (mongo.processed(err, res)) {
-                    var space_ids = spaces.map(function(value) {
-                        return value._id;
-                    });
+            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
(errSpace, spaces) => {
+                if (mongo.processed(errSpace, res)) {
+                    const space_ids = spaces.map((value) => value._id);
 
                     // Get all caches for spaces.
-                    mongo.Cache.find({space: {$in: space_ids}}).sort('name').deepPopulate('domains').exec(function(err,
caches) {
-                        if (mongo.processed(err, res)) {
+                    mongo.Cache.find({space: {$in: space_ids}}).sort('name').deepPopulate('domains').exec((errCache,
caches) => {
+                        if (mongo.processed(errCache, res)) {
                             // Get all IGFSs for spaces.
-                            mongo.Igfs.find({space: {$in: space_ids}}).sort('name').exec(function(err,
igfss) {
-                                if (mongo.processed(err, res))
-                                // Get all clusters for spaces.
-                                    mongo.Cluster.find({space: {$in: space_ids}}).sort('name').deepPopulate(mongo.ClusterDefaultPopulate).exec(function(err,
clusters) {
-                                        if (mongo.processed(err, res)) {
-                                            _.forEach(caches, function(cache) {
+                            mongo.Igfs.find({space: {$in: space_ids}}).sort('name').exec((errIgfs,
igfss) => {
+                                if (mongo.processed(errIgfs, res)) {
+                                    // Get all clusters for spaces.
+                                    mongo.Cluster.find({space: {$in: space_ids}}).sort('name').deepPopulate(mongo.ClusterDefaultPopulate).exec((errCluster,
clusters) => {
+                                        if (mongo.processed(errCluster, res)) {
+                                            _.forEach(caches, (cache) => {
                                                 // Remove deleted caches.
-                                                cache.clusters = _.filter(cache.clusters,
function(clusterId) {
+                                                cache.clusters = _.filter(cache.clusters,
(clusterId) => {
                                                     return _.find(clusters, {_id: clusterId});
                                                 });
                                             });
 
-                                            _.forEach(igfss, function(igfs) {
+                                            _.forEach(igfss, (igfs) => {
                                                 // Remove deleted caches.
-                                                igfs.clusters = _.filter(igfs.clusters, function(clusterId)
{
+                                                igfs.clusters = _.filter(igfs.clusters, (clusterId)
=> {
                                                     return _.find(clusters, {_id: clusterId});
                                                 });
                                             });
 
-                                            _.forEach(clusters, function(cluster) {
+                                            _.forEach(clusters, (cluster) => {
                                                 // Remove deleted caches.
-                                                cluster.caches = _.filter(cluster.caches,
function(cacheId) {
+                                                cluster.caches = _.filter(cluster.caches,
(cacheId) => {
                                                     return _.find(caches, {_id: cacheId});
                                                 });
 
                                                 // Remove deleted IGFS.
-                                                cluster.igfss = _.filter(cluster.igfss, function(igfsId)
{
-                                                    return _.findIndex(igfss, function(igfs)
{
-                                                            return igfs._id.equals(igfsId);
-                                                        }) >= 0;
+                                                cluster.igfss = _.filter(cluster.igfss, (igfsId)
=> {
+                                                    return _.findIndex(igfss, (igfs) =>
{
+                                                        return igfs._id.equals(igfsId);
+                                                    }) >= 0;
                                                 });
                                             });
 
-                                            res.json({
-                                                spaces: spaces,
-                                                caches: caches,
-                                                igfss: igfss,
-                                                clusters: clusters
-                                            });
+                                            res.json({ spaces, caches, igfss, clusters });
                                         }
                                     });
+                                }
                             });
                         }
                     });
@@ -97,35 +91,37 @@ module.exports.factory = function(_, express, mongo) {
         /**
          * Save cluster.
          */
-        router.post('/save', function(req, res) {
-            var params = req.body;
-            var clusterId = params._id;
-            var caches = params.caches;
-
-            if (params._id)
-                mongo.Cluster.update({_id: params._id}, params, {upsert: true}, function(err)
{
-                    if (mongo.processed(err, res))
-                        mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {clusters: clusterId}},
{multi: true}, function(err) {
-                            if (mongo.processed(err, res)) {
-                                mongo.Cache.update({_id: {$nin: caches}}, {$pull: {clusters:
clusterId}}, {multi: true}, function(err) {
-                                    if (mongo.processed(err, res))
+        router.post('/save', (req, res) => {
+            const params = req.body;
+            const caches = params.caches;
+            let clusterId = params._id;
+
+            if (params._id) {
+                mongo.Cluster.update({_id: params._id}, params, {upsert: true}, (errCluster)
=> {
+                    if (mongo.processed(errCluster, res)) {
+                        mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {clusters: clusterId}},
{multi: true}, (errCacheAdd) => {
+                            if (mongo.processed(errCacheAdd, res)) {
+                                mongo.Cache.update({_id: {$nin: caches}}, {$pull: {clusters:
clusterId}}, {multi: true}, (errCachePull) => {
+                                    if (mongo.processed(errCachePull, res))
                                         res.send(params._id);
                                 });
                             }
                         });
+                    }
                 });
+            }
             else {
-                mongo.Cluster.findOne({space: params.space, name: params.name}, function(err,
cluster) {
-                    if (mongo.processed(err, res)) {
-                        if (cluster)
-                            return res.status(500).send('Cluster with name: "' + cluster.name
+ '" already exist.');
+                mongo.Cluster.findOne({space: params.space, name: params.name}, (errClusterFound,
clusterFound) => {
+                    if (mongo.processed(errClusterFound, res)) {
+                        if (clusterFound)
+                            return res.status(500).send('Cluster with name: "' + clusterFound.name
+ '" already exist.');
 
-                        (new mongo.Cluster(params)).save(function(err, cluster) {
-                            if (mongo.processed(err, res)) {
+                        (new mongo.Cluster(params)).save((errCluster, cluster) => {
+                            if (mongo.processed(errCluster, res)) {
                                 clusterId = cluster._id;
 
-                                mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {clusters:
clusterId}}, {multi: true}, function(err) {
-                                    if (mongo.processed(err, res))
+                                mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {clusters:
clusterId}}, {multi: true}, (errCacheAdd) => {
+                                    if (mongo.processed(errCacheAdd, res))
                                         res.send(clusterId);
                                 });
                             }
@@ -138,8 +134,8 @@ module.exports.factory = function(_, express, mongo) {
         /**
          * Remove cluster by ._id.
          */
-        router.post('/remove', function(req, res) {
-            mongo.Cluster.remove(req.body, function(err) {
+        router.post('/remove', (req, res) => {
+            mongo.Cluster.remove(req.body, (err) => {
                 if (err)
                     return res.status(500).send(err.message);
 
@@ -150,26 +146,25 @@ module.exports.factory = function(_, express, mongo) {
         /**
          * Remove all clusters.
          */
-        router.post('/remove/all', function(req, res) {
-            var user_id = req.currentUserId();
+        router.post('/remove/all', (req, res) => {
+            const user_id = req.currentUserId();
 
             // Get owned space and all accessed space.
-            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
function(err, spaces) {
-                if (mongo.processed(err, res)) {
-                    var space_ids = spaces.map(function(value) {
-                        return value._id;
-                    });
-
-                    mongo.Cluster.remove({space: {$in: space_ids}}, function(err) {
-                        if (err)
-                            return res.status(500).send(err.message);
-
-                        mongo.Cache.update({space: {$in: space_ids}}, {clusters: []}, {multi:
true}, function(err) {
-                            if (mongo.processed(err, res))
-                                mongo.Igfs.update({space: {$in: space_ids}}, {clusters: []},
{multi: true}, function(err) {
-                                    if (mongo.processed(err, res))
+            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
(errSpace, spaces) => {
+                if (mongo.processed(errSpace, res)) {
+                    const space_ids = spaces.map((value) => value._id);
+
+                    mongo.Cluster.remove({space: {$in: space_ids}}, (errCluster) => {
+                        if (errCluster)
+                            return res.status(500).send(errCluster.message);
+
+                        mongo.Cache.update({space: {$in: space_ids}}, {clusters: []}, {multi:
true}, (errCache) => {
+                            if (mongo.processed(errCache, res)) {
+                                mongo.Igfs.update({space: {$in: space_ids}}, {clusters: []},
{multi: true}, (errIgfs) => {
+                                    if (mongo.processed(errIgfs, res))
                                         res.sendStatus(200);
                                 });
+                            }
                         });
                     });
                 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/33061ca9/modules/control-center-web/src/main/js/serve/routes/domains.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/domains.js b/modules/control-center-web/src/main/js/serve/routes/domains.js
index 43240ec..c2417a1 100644
--- a/modules/control-center-web/src/main/js/serve/routes/domains.js
+++ b/modules/control-center-web/src/main/js/serve/routes/domains.js
@@ -32,45 +32,41 @@ module.exports.factory = function(_, express, async, mongo) {
          * @param req Request.
          * @param res Response.
          */
-        router.post('/list', function(req, res) {
-            var user_id = req.currentUserId();
+        router.post('/list', (req, res) => {
+            const user_id = req.currentUserId();
 
             // Get owned space and all accessed space.
-            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
function(err, spaces) {
-                if (mongo.processed(err, res)) {
-                    var space_ids = spaces.map(function(value) {
-                        return value._id;
-                    });
+            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
(errSpace, spaces) => {
+                if (mongo.processed(errSpace, res)) {
+                    const space_ids = spaces.map((value) => value._id);
 
                     // Get all clusters for spaces.
-                    mongo.Cluster.find({space: {$in: space_ids}}, '_id name').sort('name').exec(function(err,
clusters) {
-                        if (mongo.processed(err, res)) {
+                    mongo.Cluster.find({space: {$in: space_ids}}, '_id name').sort('name').exec((errCluster,
clusters) => {
+                        if (mongo.processed(errCluster, res)) {
                             // Get all caches for spaces.
-                            mongo.Cache.find({space: {$in: space_ids}}).sort('name').exec(function(err,
caches) {
-                                if (mongo.processed(err, res)) {
+                            mongo.Cache.find({space: {$in: space_ids}}).sort('name').exec((errCache,
caches) => {
+                                if (mongo.processed(errCache, res)) {
                                     // Get all domain models for spaces.
-                                    mongo.DomainModel.find({space: {$in: space_ids}}).sort('valueType').exec(function(err,
domains) {
-                                        if (mongo.processed(err, res)) {
-                                            _.forEach(caches, function(cache) {
-                                                cache.domains = _.filter(cache.domains, function(metaId)
{
+                                    mongo.DomainModel.find({space: {$in: space_ids}}).sort('valueType').exec((errDomainModel,
domains) => {
+                                        if (mongo.processed(errDomainModel, res)) {
+                                            _.forEach(caches, (cache) => {
+                                                cache.domains = _.filter(cache.domains, (metaId)
=> {
                                                     return _.find(domains, {_id: metaId});
                                                 });
                                             });
 
                                             // Remove deleted caches.
-                                            _.forEach(domains, function(domain) {
-                                                domain.caches = _.filter(domain.caches, function(cacheId)
{
+                                            _.forEach(domains, (domain) => {
+                                                domain.caches = _.filter(domain.caches, (cacheId)
=> {
                                                     return _.find(caches, {_id: cacheId});
                                                 });
                                             });
 
                                             res.json({
-                                                spaces: spaces,
-                                                clusters: clusters.map(function(cluster)
{
-                                                    return {value: cluster._id, label: cluster.name};
-                                                }),
-                                                caches: caches,
-                                                domains: domains
+                                                spaces,
+                                                clusters: clusters.map((cluster) => ({value:
cluster._id, label: cluster.name})),
+                                                caches,
+                                                domains
                                             });
                                         }
                                     });
@@ -83,49 +79,52 @@ module.exports.factory = function(_, express, async, mongo) {
         });
 
         function _saveDomainModel(domain, savedDomains, callback) {
-            var domainId = domain._id;
-            var caches = domain.caches;
-
-            var cacheStoreChanges = domain.cacheStoreChanges;
-
-            if (domainId)
-                mongo.DomainModel.update({_id: domain._id}, domain, {upsert: true}, function(err)
{
-                    if (err)
-                        callback(err);
-                    else
-                        mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {domains: domainId}},
{multi: true}, function(err) {
-                            if (err)
-                                callback(err);
-                            else
-                                mongo.Cache.update({_id: {$nin: caches}}, {$pull: {domains:
domainId}}, {multi: true}, function(err) {
-                                    if (err)
-                                        callback(err);
+            const caches = domain.caches;
+            let domainId = domain._id;
+
+            const cacheStoreChanges = domain.cacheStoreChanges;
+
+            if (domainId) {
+                mongo.DomainModel.update({_id: domain._id}, domain, {upsert: true}, (errDomainModel)
=> {
+                    if (errDomainModel)
+                        callback(errDomainModel);
+                    else {
+                        mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {domains: domainId}},
{multi: true}, (errCacheAdd) => {
+                            if (errCacheAdd)
+                                callback(errCacheAdd);
+                            else {
+                                mongo.Cache.update({_id: {$nin: caches}}, {$pull: {domains:
domainId}}, {multi: true}, (errCachePull) => {
+                                    if (errCachePull)
+                                        callback(errCachePull);
                                     else {
                                         savedDomains.push(domain);
 
                                         _updateCacheStore(cacheStoreChanges, callback);
                                     }
                                 });
+                            }
                         });
+                    }
                 });
-            else
-                mongo.DomainModel.findOne({space: domain.space, valueType: domain.valueType},
function(err, found) {
-                    if (err)
-                        callback(err);
+            }
+            else {
+                mongo.DomainModel.findOne({space: domain.space, valueType: domain.valueType},
(errDomainModelFind, found) => {
+                    if (errDomainModelFind)
+                        callback(errDomainModelFind);
                     else if (found)
                         return callback('Domain model with value type: "' + found.valueType
+ '" already exist.');
 
-                    (new mongo.DomainModel(domain)).save(function(err, domain) {
-                        if (err)
-                            callback(err);
+                    (new mongo.DomainModel(domain)).save((errDomainModel, domainSaved) =>
{
+                        if (errDomainModel)
+                            callback(errDomainModel);
                         else {
-                            domainId = domain._id;
+                            domainId = domainSaved._id;
 
-                            mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {domains:
domainId}}, {multi: true}, function(err) {
-                                if (err)
-                                    callback(err);
+                            mongo.Cache.update({_id: {$in: caches}}, {$addToSet: {domains:
domainId}}, {multi: true}, (errCache) => {
+                                if (errCache)
+                                    callback(errCache);
                                 else {
-                                    savedDomains.push(domain);
+                                    savedDomains.push(domainSaved);
 
                                     _updateCacheStore(cacheStoreChanges, callback);
                                 }
@@ -133,16 +132,17 @@ module.exports.factory = function(_, express, async, mongo) {
                         }
                     });
                 });
+            }
         }
 
         function _updateCacheStore(cacheStoreChanges, callback) {
             if (cacheStoreChanges && cacheStoreChanges.length > 0) {
-                async.forEachOf(cacheStoreChanges, function(change, idx, callback) {
-                    mongo.Cache.update({_id: {$eq: change.cacheId}}, change.change, {}, function(err)
{
+                async.forEachOf(cacheStoreChanges, (change, idx, cb) => {
+                    mongo.Cache.update({_id: {$eq: change.cacheId}}, change.change, {}, (err)
=> {
                         if (err)
-                            callback(err);
+                            cb(err);
                         else
-                            callback();
+                            cb();
                     });
                 }, callback);
             }
@@ -151,31 +151,31 @@ module.exports.factory = function(_, express, async, mongo) {
         }
 
         function _save(domains, res) {
-            var savedDomains = [];
-            var generatedCaches = [];
+            const savedDomains = [];
+            const generatedCaches = [];
 
-            if (domains && domains.length > 0)
-                async.forEachOf(domains, function(domain, idx, callback) {
+            if (domains && domains.length > 0) {
+                async.forEachOf(domains, (domain, idx, callback) => {
                     if (domain.newCache) {
-                        mongo.Cache.findOne({space: domain.space, name: domain.newCache.name},
function(err, cache) {
-                            if (mongo.processed(err, res))
-                                if (cache) {
+                        mongo.Cache.findOne({space: domain.space, name: domain.newCache.name},
(errCacheFind, cacheFound) => {
+                            if (mongo.processed(errCacheFind, res)) {
+                                if (cacheFound) {
                                     // Cache already exists, just save domain model.
-                                    domain.caches = [cache._id];
+                                    domain.caches = [cacheFound._id];
 
                                     _saveDomainModel(domain, savedDomains, callback);
                                 }
                                 else {
                                     // If cache not found, then create it and associate with
domain model.
-                                    var newCache = domain.newCache;
+                                    const newCache = domain.newCache;
                                     newCache.space = domain.space;
 
-                                    (new mongo.Cache(newCache)).save(function(err, cache)
{
-                                        var cacheId = cache._id;
+                                    (new mongo.Cache(newCache)).save((errCache, cache) =>
{
+                                        const cacheId = cache._id;
 
-                                        if (mongo.processed(err, res)) {
-                                            mongo.Cluster.update({_id: {$in: cache.clusters}},
{$addToSet: {caches: cacheId}}, {multi: true}, function(err) {
-                                                if (mongo.processed(err, res)) {
+                                        if (mongo.processed(errCache, res)) {
+                                            mongo.Cluster.update({_id: {$in: cache.clusters}},
{$addToSet: {caches: cacheId}}, {multi: true}, (errCluster) => {
+                                                if (mongo.processed(errCluster, res)) {
                                                     domain.caches = [cacheId];
                                                     generatedCaches.push(cache);
 
@@ -185,16 +185,18 @@ module.exports.factory = function(_, express, async, mongo) {
                                         }
                                     });
                                 }
+                            }
                         });
                     }
                     else
                         _saveDomainModel(domain, savedDomains, callback);
-                }, function(err) {
+                }, (err) => {
                     if (err)
                         res.status(500).send(err.message);
                     else
-                        res.send({savedDomains: savedDomains, generatedCaches: generatedCaches});
+                        res.send({savedDomains, generatedCaches});
                 });
+            }
             else
                 res.status(500).send('Nothing to save!');
         }
@@ -202,22 +204,22 @@ module.exports.factory = function(_, express, async, mongo) {
         /**
          * Save domain model.
          */
-        router.post('/save', function(req, res) {
+        router.post('/save', (req, res) => {
             _save([req.body], res);
         });
 
         /**
          * Batch save domain models.
          */
-        router.post('/save/batch', function(req, res) {
+        router.post('/save/batch', (req, res) => {
             _save(req.body, res);
         });
 
         /**
          * Remove domain model by ._id.
          */
-        router.post('/remove', function(req, res) {
-            mongo.DomainModel.remove(req.body, function(err) {
+        router.post('/remove', (req, res) => {
+            mongo.DomainModel.remove(req.body, (err) => {
                 if (mongo.processed(err, res))
                     res.sendStatus(200);
             });
@@ -226,22 +228,20 @@ module.exports.factory = function(_, express, async, mongo) {
         /**
          * Remove all domain models.
          */
-        router.post('/remove/all', function(req, res) {
-            var user_id = req.currentUserId();
+        router.post('/remove/all', (req, res) => {
+            const user_id = req.currentUserId();
 
             // Get owned space and all accessed space.
-            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
function(err, spaces) {
-                if (mongo.processed(err, res)) {
-                    var space_ids = spaces.map(function(value) {
-                        return value._id;
-                    });
+            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
(errSpace, spaces) => {
+                if (mongo.processed(errSpace, res)) {
+                    const space_ids = spaces.map((value) => value._id);
 
-                    mongo.DomainModel.remove({space: {$in: space_ids}}, function(err) {
-                        if (err)
-                            return res.status(500).send(err.message);
+                    mongo.DomainModel.remove({space: {$in: space_ids}}, (errDomainModel)
=> {
+                        if (errDomainModel)
+                            return res.status(500).send(errDomainModel.message);
 
-                        mongo.Cache.update({space: {$in: space_ids}}, {domains: []}, {multi:
true}, function(err) {
-                            if (mongo.processed(err, res))
+                        mongo.Cache.update({space: {$in: space_ids}}, {domains: []}, {multi:
true}, (errCache) => {
+                            if (mongo.processed(errCache, res))
                                 res.sendStatus(200);
                         });
                     });
@@ -252,25 +252,23 @@ module.exports.factory = function(_, express, async, mongo) {
         /**
          * Remove all generated demo domain models and caches.
          */
-        router.post('/remove/demo', function(req, res) {
-            var user_id = req.currentUserId();
+        router.post('/remove/demo', (req, res) => {
+            const user_id = req.currentUserId();
 
             // Get owned space and all accessed space.
-            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
function(err, spaces) {
-                if (mongo.processed(err, res)) {
-                    var space_ids = spaces.map(function(value) {
-                        return value._id;
-                    });
+            mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
(errSpace, spaces) => {
+                if (mongo.processed(errSpace, res)) {
+                    const space_ids = spaces.map((value) => value._id);
 
                     // Remove all demo domain models.
-                    mongo.DomainModel.remove({$and: [{space: {$in: space_ids}}, {demo: true}]},
function(err) {
-                        if (err)
-                            return res.status(500).send(err.message);
+                    mongo.DomainModel.remove({$and: [{space: {$in: space_ids}}, {demo: true}]},
(errDomainModel) => {
+                        if (errDomainModel)
+                            return res.status(500).send(errDomainModel.message);
 
                         // Remove all demo caches.
-                        mongo.Cache.remove({$and: [{space: {$in: space_ids}}, {demo: true}]},
function(err) {
-                            if (err)
-                                return res.status(500).send(err.message);
+                        mongo.Cache.remove({$and: [{space: {$in: space_ids}}, {demo: true}]},
(errCache) => {
+                            if (errCache)
+                                return res.status(500).send(errCache.message);
 
                             res.sendStatus(200);
                         });


Mime
View raw message