Answer the question
In order to leave comments, you need to log in
How to properly validate angular + mongoose fields?
There is a model
var ArticleSchema = new Schema({
created: {
type: Date,
default: Date.now
},
title: {
ru: [{
type: String,
default: '',
trim: true,
required: 'Заголовок не может быть пустым'
}],
en: [{
type: String,
default: '',
trim: true,
required: 'Title cannot be blank'
}]
},
content: {
type: String,
default: '',
trim: true
},
user: {
type: Schema.ObjectId,
ref: 'User'
}
});
exports.create = function(req, res) {
var article = new Article(req.body);
article.user = req.user;
console.dir(req.body);
article.save(function(err) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.json(article);
}
});
};
$scope.create = function() {
var article = new Articles({
title: this.title,
content: this.content
});
article.$save(function(response) {
$location.path('articles/' + response._id);
$scope.title.ru = '';
$scope.title.en = '';
$scope.content = '';
}, function(errorResponse) {
$scope.error = errorResponse.data.message;
});
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question