ozserver
Version:
API for OZ
50 lines (39 loc) • 1.58 kB
JavaScript
var EventEmitter, Post, Schema, exports, validate,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
validate = require('validate');
EventEmitter = require('events').EventEmitter;
Schema = require(global.home + '/script/views/validate/post');
Post = (function(_super) {
__extends(Post, _super);
function Post(model) {
this.model = model != null ? model : {};
this.on('success', function() {
this.model.success = true;
return this.model.notice = 'Сообщение успешно добавлено';
});
this.on('userNotFound', function() {
this.model.success = false;
return this.model.notice = 'Не удалось добавить комментарий';
});
}
Post.prototype.check = function() {
this.model.success = false;
this.model.message.text = this.model.message.text.toString().trim();
this.model.notice = validate(Schema, this.model);
if (Array.isArray(this.model.notice)) {
this.model.notice = this.model.notice[0].toString().replace('Error: ', '');
} else {
this.model.success = true;
}
return this.model.success;
};
return Post;
})(EventEmitter);
exports = module.exports = function(model) {
if (model == null) {
model = {};
}
return new Post(model);
};
exports.Post = Post;