Skip to content

Commit

Permalink
MySQL is updated if user remembers word
Browse files Browse the repository at this point in the history
  • Loading branch information
githubalexliu committed Mar 20, 2018
1 parent 5c615af commit 1b25af6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions app/review.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function(req, res) {
remword = function(userid, wordid) {
connection.query("UPDATE ?? SET progress = progress + 1, daterev = ADDDATE(daterev, 2*progress) WHERE id = ?",
[userid, wordid], function(err, rows) {
if (err) throw err;
});
}
};
var mysql = require('mysql');
var dbconfig = require('../config/database');
var bcrypt = require('bcrypt-nodejs');
var connection = mysql.createConnection(dbconfig.connection);
connection.query('USE ' + dbconfig.database);
6 changes: 6 additions & 0 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ module.exports = function(app, passport) {
res.redirect('/');
}
});

app.post('/remword', function(req, res) {
remword(req.user.id, req.body.id);
});

app.get('/logout', function(req, res) {
req.logout();
res.redirect('/');
Expand All @@ -147,6 +152,7 @@ var connection = mysql.createConnection(dbconfig.connection);
connection.query('USE ' + dbconfig.database);
require('./profile.js')();
require('./word-list.js')();
require('./review.js')();

function isLoggedIn(req, res, next) {
if (req.isAuthenticated())
Expand Down
10 changes: 8 additions & 2 deletions views/review.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<script type="text/javascript">
$(document).ready(function() {
var wordlist = <%- JSON.stringify(wordlist) %>;
console.log(wordlist);
var word = document.getElementById('word');
var numRemain = document.getElementById('numRemain');
var showMean = document.getElementById('showMean');
Expand All @@ -30,6 +29,13 @@
dontRem.disabled = false;
});
$('#rem').on('click', function() {
$.ajax({
url: "/remword",
type: "post",
data: {
id: wordlist[0].id
}
});
wordlist.shift();
this.disabled = true;
dontRem.disabled = true;
Expand Down Expand Up @@ -61,7 +67,7 @@
<% include partials/nav %>
<div class="container-fluid text-center top-buffer-50">
<label>Number of words left:</label>
<label id="numRemain">3</label>
<label id="numRemain"></label>
<div class="review-word" id="word"></div>
<textarea class="top-buffer-20 review-meaning" rows="5" cols="40" id="meaning" readonly></textarea>
<div class="row top-buffer-20">
Expand Down

0 comments on commit 1b25af6

Please sign in to comment.