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,20 +137,34 @@ 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.forge({id: req.body.id})
.destroy()
.then(function() {
res.json({
error: {
error: false,
message: ''
},
code: 'B137',
data: {}
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
});
})
.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({
error: {
error: true,
@ -161,7 +176,7 @@ module.exports = function(app) {
}
})
});
});
});
app.get('/users/:id',function(req,res){

@ -148,31 +148,34 @@ class Admin extends React.Component {
deleteUser(id,e) {
e.preventDefault();
var myHeaders = new Headers({
"Content-Type": "application/x-www-form-urlencoded",
"x-access-token": window.localStorage.getItem('userToken')
});
var myInit = { method: 'DELETE',
headers: myHeaders,
body: "id="+id
};
var that = this;
fetch('/api/users/',myInit)
.then(function(response) {
return response.json();
})
.then(function(response) {
if(response.error.error)
Alert.error(response.error.message);
else {
users = that.state.users
var users = $.grep(users, function(e){
return e.id != id;
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')
});
that.setState({users: users});
Alert.success('User has been deleted');
}
});
var myInit = { method: 'DELETE',
headers: myHeaders,
body: "id="+id
};
var that = this;
fetch('/api/users/',myInit)
.then(function(response) {
return response.json();
})
.then(function(response) {
if(response.error.error)
Alert.error(response.error.message);
else {
users = that.state.users
var users = $.grep(users, function(e){
return e.id != id;
});
that.setState({users: users});
Alert.success('User has been deleted');
}
});
}
}

@ -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