function getJSONObj(json_input) { if (typeof json_input == "string") return $.parseJSON(json_input) else if (typeof json_input == "object") return json_input; console.error("Unable to parse json:", json_input); return null } function User() { this.UserId = -1; this.Name = ""; this.Username = ""; this.Password = ""; this.Email = ""; } User.prototype.toJSON = function() { var json_obj = {}; json_obj.UserId = this.UserId; json_obj.Name = this.Name; json_obj.Username = this.Username; json_obj.Password = this.Password; json_obj.Email = this.Email; return JSON.stringify(json_obj); } User.prototype.fromJSON = function(json_input) { var json_obj = getJSONObj(json_input); if (json_obj.hasOwnProperty("UserId")) this.UserId = json_obj.UserId; if (json_obj.hasOwnProperty("Name")) this.Name = json_obj.Name; if (json_obj.hasOwnProperty("Username")) this.Username = json_obj.Username; if (json_obj.hasOwnProperty("Password")) this.Password = json_obj.Password; if (json_obj.hasOwnProperty("Email")) this.Email = json_obj.Email; } User.prototype.isUser = function() { var empty_user = new User(); return this.UserId != empty_user.UserId || this.Username != empty_user.Username; } function Session() { this.SessionId = -1; this.UserId = -1; } Session.prototype.toJSON = function() { var json_obj = {}; json_obj.SessionId = this.SessionId; json_obj.UserId = this.UserId; return JSON.stringify(json_obj); } Session.prototype.fromJSON = function(json_input) { var json_obj = getJSONObj(json_input); if (json_obj.hasOwnProperty("SessionId")) this.SessionId = json_obj.SessionId; if (json_obj.hasOwnProperty("UserId")) this.UserId = json_obj.UserId; } Session.prototype.isSession = function() { var empty_session = new Session(); return this.SessionId != empty_session.SessionId || this.UserId != empty_session.UserId; } function Attendee() { this.AttendeeId = -1; this.Name = ""; } Attendee.prototype.toJSON = function() { var json_obj = {}; json_obj.AttendeeId = this.AttendeeId; json_obj.Name = this.Name; return JSON.stringify(json_obj); } Attendee.prototype.fromJSON = function(json_input) { var json_obj = getJSONObj(json_input); if (json_obj.hasOwnProperty("AttendeeId")) this.AttendeeId = json_obj.AttendeeId; if (json_obj.hasOwnProperty("Name")) this.Name = json_obj.Name; } Attendee.prototype.isAttendee = function() { var empty_attendee = new Attendee(); return this.AttendeeId != empty_attendee.AttendeeId || this.Name != empty_attendee.Name; } function PopularAttendee() { this.Name = ""; this.Popularity = 0; } PopularAttendee.prototype.toJSON = function() { var json_obj = {}; json_obj.Name = this.Name; json_obj.Popularity = this.Popularity; return JSON.stringify(json_obj); } PopularAttendee.prototype.fromJSON = function(json_input) { var json_obj = getJSONObj(json_input); if (json_obj.hasOwnProperty("Popularity")) this.Popularity = json_obj.Popularity; if (json_obj.hasOwnProperty("Name")) this.Name = json_obj.Name; } PopularAttendee.prototype.isPopularAttendee = function() { var empty_attendee = new PopularAttendee(); return this.Popularity != empty_attendee.Popularity || this.Name != empty_attendee.Name; } function Suggestion() { this.SuggestionId = -1; this.VetoingId = -1; this.AttendeeId = -1; this.RestaurantName = ""; } Suggestion.prototype.toJSON = function() { var json_obj = {}; json_obj.SuggestionId = this.SuggestionId; json_obj.VetoingId = this.VetoingId; json_obj.AttendeeId = this.AttendeeId; json_obj.RestaurantName = this.RestaurantName; return JSON.stringify(json_obj); } Suggestion.prototype.fromJSON = function(json_input) { var json_obj = getJSONObj(json_input); if (json_obj.hasOwnProperty("SuggestionId")) this.SuggestionId = json_obj.SuggestionId; if (json_obj.hasOwnProperty("VetoingId")) this.VetoingId = json_obj.VetoingId; if (json_obj.hasOwnProperty("AttendeeId")) this.AttendeeId = json_obj.AttendeeId; if (json_obj.hasOwnProperty("RestaurantName")) this.RestaurantName = json_obj.RestaurantName; } Suggestion.prototype.isSuggestion = function() { var empty_suggestion = new Suggestion(); return this.SuggestionId != empty_suggestion.SuggestionId && this.AttendeeId != empty_suggestion.AttendeeId && this.RestaurantName != empty_suggestion.RestaurantName; } function PopularSuggestion() { this.RestaurantName = ""; this.Popularity = 0; } PopularSuggestion.prototype.toJSON = function() { var json_obj = {}; json_obj.RestaurantName = this.RestaurantName; json_obj.Popularity = this.Popularity; return JSON.stringify(json_obj); } PopularSuggestion.prototype.fromJSON = function(json_input) { var json_obj = getJSONObj(json_input); if (json_obj.hasOwnProperty("RestaurantName")) this.RestaurantName = json_obj.RestaurantName; if (json_obj.hasOwnProperty("Popularity")) this.Popularity = json_obj.Popularity; } PopularSuggestion.prototype.isPopularSuggestion = function() { var empty_suggestion = new PopularSuggestion(); return this.RestaurantName != empty_suggestion.RestaurantName && this.Popularity != empty_suggestion.Popularity; } function Error() { this.ErrorId = -1; this.ErrorString = ""; } Error.prototype.toJSON = function() { var json_obj = {}; json_obj.ErrorId = this.ErrorId; json_obj.ErrorString = this.ErrorString; return JSON.stringify(json_obj); } Error.prototype.fromJSON = function(json_input) { var json_obj = getJSONObj(json_input); if (json_obj.hasOwnProperty("ErrorId")) this.ErrorId = json_obj.ErrorId; if (json_obj.hasOwnProperty("ErrorString")) this.ErrorString = json_obj.ErrorString; } Error.prototype.isError = function() { var empty_error = new Error(); return this.ErrorId != empty_error.ErrorId || this.ErrorString != empty_error.ErrorString; } function Report() { this.ReportId = "invalid"; this.Title = ""; this.Data = []; } Report.prototype.toJSON = function() { var json_obj = {}; json_obj.ReportId = this.ReportId; json_obj.Title = this.Title; json_obj.Data = this.Data; return JSON.stringify(json_obj); } Report.prototype.fromJSON = function(json_input) { var json_obj = getJSONObj(json_input); if (json_obj.hasOwnProperty("ReportId")) this.ReportId = json_obj.ReportId; if (json_obj.hasOwnProperty("Title")) this.Title = json_obj.Title; if (json_obj.hasOwnProperty("Data")) this.Data = json_obj.Data; } Report.prototype.isReport = function() { var empty_report = new Report(); return this.ReportId != empty_report.ReportId || this.Title != empty_report.Title; } module.exports = models = { // Classes User: User, Session: Session, Error: Error, Attendee: Attendee, PopularAttendee: PopularAttendee, Suggestion: Suggestion, PopularSuggestion: PopularSuggestion, Report: Report, // Constants BogusPassword: "password" };