Fixed merge conflicts

chinese-translation
Nishant Arora 8 years ago
commit ba169912a1

@ -8,6 +8,7 @@ comment in the articles.js (same directory).
// Importing the topics model
var Users = require('../models/user.js');
var bcrypt = require('bcryptjs');
var Articles = require('../models/article.js');
const saltRounds = 10;
var db = require('../db.js'); //this file contains the knex file import. it's equal to knex=require('knex')
@ -136,7 +137,20 @@ module.exports = function(app) {
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
*/
Users.where({id: req.body.id}).fetch({withRelated: ['articles']}).then(function(user) {
var user = user.toJSON();
var articles = user.articles;
for(var i=0; i<articles.length; i++)
{
Articles.forge({id: articles[i].id}).save({
title: articles[i].title,
body: articles[i].body,
topic_id: articles[i].topic_id,
what_changed: articles[i].what_changed,
user_id: 1
});
}
}).then(function(){
Users.forge({id: req.body.id})
.destroy()
.then(function() {
@ -149,6 +163,7 @@ module.exports = function(app) {
data: {}
});
})
})
.catch(function (error) {
res.status(500).json({
error: {

@ -148,6 +148,8 @@ class Admin extends React.Component {
deleteUser(id,e) {
e.preventDefault();
var del = confirm("Deleting the user will move all of his/her articles to the Admin. Are you sure?");
if(del==true) {
var myHeaders = new Headers({
"Content-Type": "application/x-www-form-urlencoded",
"x-access-token": window.localStorage.getItem('userToken')
@ -174,6 +176,7 @@ class Admin extends React.Component {
}
});
}
}
render () {

@ -53,6 +53,7 @@ padding: 10px 20px;
.article-item-title {
font-size: 2.5em;
font-weight: 700;
word-wrap: break-word;
}
.article-item-title a {

@ -1,12 +1,11 @@
var bookshelf = require('../bookshelf');
bookshelf.plugin('registry');
var Articles = require('./article.js');
var Article = require('./article');
var User = bookshelf.Model.extend({
tableName: 'users',
articles: function(){
return this.hasMany('Articles');
return this.hasMany('Article');
}
});

Loading…
Cancel
Save