UNPKG

ozserver

Version:

API for OZ

51 lines (40 loc) 1.41 kB
var Personal, Schema, exports, validate; validate = require('validate'); Schema = require(global.home + '/script/views/validate/personal'); Personal = (function() { function Personal(model) { this.model = model != null ? model : {}; } Personal.prototype.check = function() { this.model.success = false; this.model.firstname_new = this.model.firstname_new.trim(); this.model.lastname_new = this.model.lastname_new.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; }; Personal.prototype.success = function() { this.model.success = true; this.model.firstname = this.model.firstname_new; this.model.lastname = this.model.lastname_new; this.model.firstname_new = null; this.model.lastname_new = null; return this.model.notice = 'Данные успешно изменены'; }; Personal.prototype.fail = function() { this.model.success = false; return this.model.notice = 'Не удалось записать новые даннные'; }; return Personal; })(); exports = module.exports = function(model) { if (model == null) { model = {}; } return new Personal(model); }; exports.Personal = Personal;