improve naming

This commit is contained in:
Simon Martín
2018-08-01 15:43:45 +02:00
parent 2a2f703abc
commit 7b7bee2901
+7 -11
View File
@@ -305,26 +305,22 @@ TemplateMaps.prototype.updTemplate = function(owner, tpl_id, template, callback)
return callback(invalidError);
}
var templateName = template.name;
if (tpl_id !== templateName) {
return callback(new Error("Cannot update name of a map template ('" + tpl_id + "' != '" + templateName + "')"));
if (tpl_id !== template.name) {
return callback(new Error("Cannot update name of a map template ('" + tpl_id + "' != '" + template.name + "')"));
}
var userTemplatesKey = this.key_usr_tpl({ owner });
var previousTemplate = null;
this._redisCmd('HGET', [userTemplatesKey, tpl_id], (err, _currentTemplate) => {
this._redisCmd('HGET', [userTemplatesKey, tpl_id], (err, beforeUpdateTemplate) => {
if (err) {
return callback(err);
}
if (!_currentTemplate) {
if (!beforeUpdateTemplate) {
return callback(new Error(`Template '${tpl_id}' of user '${owner}' does not exist`));
}
previousTemplate = _currentTemplate;
this._redisCmd('HSET', [userTemplatesKey, templateName, JSON.stringify(template)], (err, didSetNewField) => {
this._redisCmd('HSET', [userTemplatesKey, template.name, JSON.stringify(template)], (err, didSetNewField) => {
if (err) {
return callback(err);
}
@@ -333,8 +329,8 @@ TemplateMaps.prototype.updTemplate = function(owner, tpl_id, template, callback)
debug('New template created on update operation');
}
if (this.fingerPrint(JSON.parse(previousTemplate)) !== this.fingerPrint(template)) {
this.emit('update', owner, templateName, template);
if (this.fingerPrint(JSON.parse(beforeUpdateTemplate)) !== this.fingerPrint(template)) {
this.emit('update', owner, template.name, template);
}
return callback(err, template);