1

Adding code to forget categories

This commit is contained in:
Alex Yatskov 2015-03-12 11:08:34 +09:00
parent 9edb58590d
commit a316f1e3d3
3 changed files with 25 additions and 15 deletions

View File

@ -13,7 +13,7 @@
<tr>
<th></th>
<th>Category</th>
<th>Rating</th>
<th class="text-right">Rating</th>
</tr>
</thead>
<tbody id="categories"></tbody>
@ -22,7 +22,7 @@
<tr class="category_{{id}}">
<td><button type="button" data-categoryId="{{id}}" class="btn btn-xs btn-danger">&times;</button></td>
<td>{{description}}</td>
<td>
<td class="text-right">
<label class="radio-inline">
<input type="radio" name="category_{{id}}" data-categoryId="{{id}}" value="1" {{checkMatch 1}}> Agree
</label>

View File

@ -248,6 +248,16 @@ function addCategory(query, callback) {
}
}
function removeCategory(query, callback) {
pool.query('DELETE FROM categories WHERE id = (?)', [query.id], function(err, info) {
if (err) {
throw err;
}
callback({success: info.affectedRows > 0});
});
}
function accessReview(query, callback) {
pool.query('SELECT url FROM reviews WHERE id = (?) LIMIT 1', [query.id], function(err, rows) {
if (err) {
@ -266,17 +276,10 @@ function accessReview(query, callback) {
throw err;
}
var pitcher = function(err, info) {
if (err) {
throw err;
}
};
for (var categoryId in query.profile) {
pool.query(
'INSERT INTO historyGroups(categoryId, categoryValue, historyId) VALUES(?, ?, ?)',
[categoryId, query.profile[categoryId], info.insertId],
pitcher
[categoryId, query.profile[categoryId], info.insertId]
);
}
});
@ -328,9 +331,10 @@ function runQuery(query, callback) {
}
module.exports = {
loadDb: loadDb,
runQuery: runQuery,
getCategories: getCategories,
addCategory: addCategory,
accessReview: accessReview
loadDb: loadDb,
runQuery: runQuery,
getCategories: getCategories,
addCategory: addCategory,
removeCategory: removeCategory,
accessReview: accessReview
};

View File

@ -57,6 +57,12 @@ function main(staticFiles, port) {
});
});
app.use('/forget', function(req, res) {
search.removeCategory(req.query, function(results) {
res.json(results);
});
});
app.use('/access', function(req, res) {
search.accessReview(req.query, function(results) {
res.json(results);