2016-12-22 21:22:47 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-23 08:30:29 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-28 09:25:20 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-24 10:00:21 -05:00
|
|
|
function Suggestion() {
|
|
|
|
this.SuggestionId = -1;
|
|
|
|
this.VetoingId = -1;
|
|
|
|
this.AttendeeId = -1;
|
|
|
|
this.RestaurantName = "";
|
2016-12-23 20:38:59 -05:00
|
|
|
}
|
|
|
|
|
2016-12-24 10:00:21 -05:00
|
|
|
Suggestion.prototype.toJSON = function() {
|
2016-12-23 20:38:59 -05:00
|
|
|
var json_obj = {};
|
2016-12-24 10:00:21 -05:00
|
|
|
json_obj.SuggestionId = this.SuggestionId;
|
|
|
|
json_obj.AttendeeId = this.AttendeeId;
|
|
|
|
json_obj.RestaurantName = this.RestaurantName;
|
2016-12-23 20:38:59 -05:00
|
|
|
return JSON.stringify(json_obj);
|
|
|
|
}
|
|
|
|
|
2016-12-24 10:00:21 -05:00
|
|
|
Suggestion.prototype.fromJSON = function(json_input) {
|
2016-12-23 20:38:59 -05:00
|
|
|
var json_obj = getJSONObj(json_input);
|
|
|
|
|
2016-12-24 10:00:21 -05:00
|
|
|
if (json_obj.hasOwnProperty("SuggestionId"))
|
|
|
|
this.SuggestionId = json_obj.SuggestionId;
|
|
|
|
if (json_obj.hasOwnProperty("AttendeeId"))
|
|
|
|
this.AttendeeId = json_obj.AttendeeId;
|
|
|
|
if (json_obj.hasOwnProperty("RestaurantName"))
|
|
|
|
this.RestaurantName = json_obj.RestaurantName;
|
2016-12-23 20:38:59 -05:00
|
|
|
}
|
|
|
|
|
2016-12-24 10:00:21 -05:00
|
|
|
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;
|
2016-12-23 20:38:59 -05:00
|
|
|
}
|
|
|
|
|
2016-12-28 09:25:20 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-22 21:22:47 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = models = {
|
|
|
|
|
|
|
|
// Classes
|
|
|
|
User: User,
|
|
|
|
Session: Session,
|
|
|
|
Error: Error,
|
2016-12-28 09:25:20 -05:00
|
|
|
Attendee: Attendee,
|
|
|
|
PopularAttendee: PopularAttendee,
|
|
|
|
Suggestion: Suggestion,
|
|
|
|
PopularSuggestion: PopularSuggestion,
|
2016-12-22 21:22:47 -05:00
|
|
|
|
|
|
|
// Constants
|
|
|
|
BogusPassword: "password"
|
|
|
|
};
|