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> <tr>
<th></th> <th></th>
<th>Category</th> <th>Category</th>
<th>Rating</th> <th class="text-right">Rating</th>
</tr> </tr>
</thead> </thead>
<tbody id="categories"></tbody> <tbody id="categories"></tbody>
@ -22,7 +22,7 @@
<tr class="category_{{id}}"> <tr class="category_{{id}}">
<td><button type="button" data-categoryId="{{id}}" class="btn btn-xs btn-danger">&times;</button></td> <td><button type="button" data-categoryId="{{id}}" class="btn btn-xs btn-danger">&times;</button></td>
<td>{{description}}</td> <td>{{description}}</td>
<td> <td class="text-right">
<label class="radio-inline"> <label class="radio-inline">
<input type="radio" name="category_{{id}}" data-categoryId="{{id}}" value="1" {{checkMatch 1}}> Agree <input type="radio" name="category_{{id}}" data-categoryId="{{id}}" value="1" {{checkMatch 1}}> Agree
</label> </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) { function accessReview(query, callback) {
pool.query('SELECT url FROM reviews WHERE id = (?) LIMIT 1', [query.id], function(err, rows) { pool.query('SELECT url FROM reviews WHERE id = (?) LIMIT 1', [query.id], function(err, rows) {
if (err) { if (err) {
@ -266,17 +276,10 @@ function accessReview(query, callback) {
throw err; throw err;
} }
var pitcher = function(err, info) {
if (err) {
throw err;
}
};
for (var categoryId in query.profile) { for (var categoryId in query.profile) {
pool.query( pool.query(
'INSERT INTO historyGroups(categoryId, categoryValue, historyId) VALUES(?, ?, ?)', 'INSERT INTO historyGroups(categoryId, categoryValue, historyId) VALUES(?, ?, ?)',
[categoryId, query.profile[categoryId], info.insertId], [categoryId, query.profile[categoryId], info.insertId]
pitcher
); );
} }
}); });
@ -328,9 +331,10 @@ function runQuery(query, callback) {
} }
module.exports = { module.exports = {
loadDb: loadDb, loadDb: loadDb,
runQuery: runQuery, runQuery: runQuery,
getCategories: getCategories, getCategories: getCategories,
addCategory: addCategory, addCategory: addCategory,
accessReview: accessReview 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) { app.use('/access', function(req, res) {
search.accessReview(req.query, function(results) { search.accessReview(req.query, function(results) {
res.json(results); res.json(results);