1

Keyword validation

This commit is contained in:
Alex Yatskov 2014-10-03 15:28:35 +09:00
parent b587ee084c
commit 085e351245

View File

@ -175,25 +175,32 @@ function loadDb(params) {
} }
function addKeyword(query, callback) { function addKeyword(query, callback) {
getKeywords(function(keywords) { var keyword = (query.keyword || '').toLowerCase();
var keyword = query.keyword.toLowerCase(); if (!/^[a-zA-Z0-9]+$/.test(keyword)) {
var features = combine(keywords, query.params); callback({
keyword: keyword,
success: false
});
}
else {
getKeywords(function(keywords) {
var features = combine(keywords, query.params);
var values = [
keyword,
features.food || 0.0,
features.service || 0.0,
features.value || 0.0,
features.atmosphere || 0.0
];
var values = [ connection.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) {
keyword, callback({
features.food || 0.0, keyword: keyword,
features.service || 0.0, success: err === null
features.value || 0.0, });
features.atmosphere || 0.0
];
connection.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) {
callback({
keyword: keyword,
success: err === null
}); });
}); });
}); }
} }
function removeKeyword(query, callback) { function removeKeyword(query, callback) {