|
|
@ -8,6 +8,7 @@ comment in the articles.js (same directory).
|
|
|
|
// Importing the topics model
|
|
|
|
// Importing the topics model
|
|
|
|
var Users = require('../models/user.js');
|
|
|
|
var Users = require('../models/user.js');
|
|
|
|
var bcrypt = require('bcryptjs');
|
|
|
|
var bcrypt = require('bcryptjs');
|
|
|
|
|
|
|
|
var Articles = require('../models/article.js');
|
|
|
|
const saltRounds = 10;
|
|
|
|
const saltRounds = 10;
|
|
|
|
var db = require('../db.js'); //this file contains the knex file import. it's equal to knex=require('knex')
|
|
|
|
var db = require('../db.js'); //this file contains the knex file import. it's equal to knex=require('knex')
|
|
|
|
|
|
|
|
|
|
|
@ -136,20 +137,34 @@ module.exports = function(app) {
|
|
|
|
It takes the id of the user and then deletes that record from the database.
|
|
|
|
It takes the id of the user and then deletes that record from the database.
|
|
|
|
the error key in the returning object is a boolen which is false if there is no error and true otherwise
|
|
|
|
the error key in the returning object is a boolen which is false if there is no error and true otherwise
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
Users.where({id: req.body.id}).fetch({withRelated: ['articles']}).then(function(user) {
|
|
|
|
Users.forge({id: req.body.id})
|
|
|
|
var user = user.toJSON();
|
|
|
|
.destroy()
|
|
|
|
var articles = user.articles;
|
|
|
|
.then(function() {
|
|
|
|
for(var i=0; i<articles.length; i++)
|
|
|
|
res.json({
|
|
|
|
{
|
|
|
|
error: {
|
|
|
|
Articles.forge({id: articles[i].id}).save({
|
|
|
|
error: false,
|
|
|
|
title: articles[i].title,
|
|
|
|
message: ''
|
|
|
|
body: articles[i].body,
|
|
|
|
},
|
|
|
|
topic_id: articles[i].topic_id,
|
|
|
|
code: 'B137',
|
|
|
|
what_changed: articles[i].what_changed,
|
|
|
|
data: {}
|
|
|
|
user_id: 1
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
.catch(function (error) {
|
|
|
|
}).then(function(){
|
|
|
|
|
|
|
|
Users.forge({id: req.body.id})
|
|
|
|
|
|
|
|
.destroy()
|
|
|
|
|
|
|
|
.then(function() {
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
|
|
|
|
error: {
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
message: ''
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
code: 'B137',
|
|
|
|
|
|
|
|
data: {}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(function (error) {
|
|
|
|
res.status(500).json({
|
|
|
|
res.status(500).json({
|
|
|
|
error: {
|
|
|
|
error: {
|
|
|
|
error: true,
|
|
|
|
error: true,
|
|
|
@ -161,7 +176,7 @@ module.exports = function(app) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/users/:id',function(req,res){
|
|
|
|
app.get('/users/:id',function(req,res){
|
|
|
|