I've been learning to use Angular 6 and NodeJS (with ExpressJS) these past few days. To do this, I decided to create a front-end with Angular 6 (o which theres a form) with the intention of passing information back and forth to my PHPMyAdmin database via the use of an API I created with NodeJS. As you may have seen from the title, I get the following error when I try to submit my forms information:
"Unhandled rejection TypeError: callback is not a function"
The code I used for the post action was taken from another functioning and similar API, the database receives the question_id and user_id but will not register the questions answers (which is the end goal). Without furthur ado, here is the code to get and post:
const config = require('../config/config');
const knex = config.db.knex;
const async = require('async');
class TestModel {
getQuestions(callback) {
knex('question')
.select('id', 'libelle')
.orderBy('id', 'asc')
.then((data) => {
callback(data);
});
}
addResponse(reponse, callback) {
knex('reponse')
.insert({
id_user : 1,
id_question : reponse.id,
libelle: reponse.answer,
}).then((data) => {
callback(data);
});
}
}
module.exports = new TestModel();
Here is the rest:
app.post('/quiz', function(req, res, next){
var answers = req.body;
console.log(answers)
for(var i = 0; i<answers.length; i++)
{
var obj = answers[i];
Test.addResponse((obj,result) => {
});
}
res.json({reponseserveur:'True'});
});
Just for reference, "reponse" means response and "libelle" means label. Thanks in advance for your help!