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 // 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){

@ -148,31 +148,34 @@ class Admin extends React.Component {
deleteUser(id,e) { deleteUser(id,e) {
e.preventDefault(); e.preventDefault();
var myHeaders = new Headers({ var del = confirm("Deleting the user will move all of his/her articles to the Admin. Are you sure?");
"Content-Type": "application/x-www-form-urlencoded", if(del==true) {
"x-access-token": window.localStorage.getItem('userToken') var myHeaders = new Headers({
}); "Content-Type": "application/x-www-form-urlencoded",
var myInit = { method: 'DELETE', "x-access-token": window.localStorage.getItem('userToken')
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}); var myInit = { method: 'DELETE',
Alert.success('User has been deleted'); 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 { .article-item-title {
font-size: 2.5em; font-size: 2.5em;
font-weight: 700; font-weight: 700;
word-wrap: break-word;
} }
.article-item-title a { .article-item-title a {

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

Loading…
Cancel
Save