Skip to content

Commit 5d64dd5

Browse files
Stanislavvengrov
authored andcommitted
Remove restriction for using Backendless.Data.of('Users') notation (#85)
* Remove restriction for using Backendless.Data.of('Users') notation Do not remove user-token from User object * refactor
1 parent b905689 commit 5d64dd5

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

libs/backendless.js

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,15 +1358,15 @@
13581358
},
13591359
of: function(model) {
13601360
var tableName;
1361+
13611362
if (Utils.isString(model)) {
1362-
if (model.toLowerCase() === 'users') {
1363-
throw new Error("Table 'Users' is not accessible through this signature. Use Backendless.Data.of( BackendlessUser.class ) instead");
1364-
}
13651363
tableName = model;
13661364
} else {
13671365
tableName = getClassName.call(model);
13681366
}
1367+
13691368
var store = dataStoreCache[tableName];
1369+
13701370
if (!store) {
13711371
store = new DataStore(model);
13721372
dataStoreCache[tableName] = store;
@@ -1484,7 +1484,12 @@
14841484
}
14851485
};
14861486

1487-
function User() {
1487+
function User(user) {
1488+
user = user || {};
1489+
1490+
for (var prop in user) {
1491+
this[prop] = user[prop]
1492+
}
14881493
}
14891494

14901495
User.prototype.___class = "Users";
@@ -1585,9 +1590,9 @@
15851590
return this.roleHelper(identity, rolename, async, 'unassignRole');
15861591
},
15871592

1588-
login: function(username, password, stayLoggedIn, async) {
1589-
if (!username) {
1590-
throw new Error('Username can not be empty');
1593+
login: function(login, password, stayLoggedIn, async) {
1594+
if (!login) {
1595+
throw new Error('Login can not be empty');
15911596
}
15921597

15931598
if (!password) {
@@ -1608,7 +1613,7 @@
16081613
}
16091614

16101615
var data = {
1611-
login : username,
1616+
login : login,
16121617
password: password
16131618
};
16141619

@@ -1631,21 +1636,13 @@
16311636
_getUserFromResponse: function(user) {
16321637
Backendless.LocalCache.set("current-user-id", user.objectId);
16331638

1634-
var newUser = new Backendless.User();
1639+
var userToken = user['user-token']
16351640

1636-
for (var i in user) {
1637-
if (user.hasOwnProperty(i)) {
1638-
if (i == 'user-token') {
1639-
if (Backendless.LocalCache.get("stayLoggedIn")) {
1640-
Backendless.LocalCache.set("user-token", user[i]);
1641-
}
1642-
continue;
1643-
}
1644-
newUser[i] = user[i];
1645-
}
1641+
if (userToken && Backendless.LocalCache.get('stayLoggedIn')) {
1642+
Backendless.LocalCache.set('user-token', userToken)
16461643
}
16471644

1648-
return newUser;
1645+
return new Backendless.User(user);
16491646
},
16501647

16511648
loggedInUser: function() {
@@ -4498,11 +4495,13 @@
44984495
currentUser = null;
44994496
};
45004497

4501-
var DataQuery = function () {
4502-
this.properties = [];
4503-
this.condition = null;
4504-
this.options = null;
4505-
this.url = null;
4498+
var DataQuery = function (args) {
4499+
args = args || {};
4500+
4501+
this.properties = args.properties || [];
4502+
this.condition = args.condition || null;
4503+
this.options = args.options || null;
4504+
this.url = args.url || null;
45064505
};
45074506

45084507
DataQuery.prototype = {
@@ -4512,21 +4511,23 @@
45124511
}
45134512
};
45144513

4515-
var GeoQuery = function() {
4516-
this.searchRectangle = undefined;
4517-
this.categories = [];
4518-
this.includeMetadata = true;
4519-
this.metadata = undefined;
4520-
this.condition = undefined;
4521-
this.relativeFindMetadata = undefined;
4522-
this.relativeFindPercentThreshold = undefined;
4523-
this.pageSize = undefined;
4524-
this.latitude = undefined;
4525-
this.longitude = undefined;
4526-
this.radius = undefined;
4527-
this.units = undefined;
4528-
this.degreePerPixel = undefined;
4529-
this.clusterGridSize = undefined;
4514+
var GeoQuery = function(args) {
4515+
args = args || {};
4516+
4517+
this.searchRectangle = args.searchRectangle || undefined;
4518+
this.categories = args.categories || [];
4519+
this.includeMetadata = args.includeMetadata || true;
4520+
this.metadata = args.metadata || undefined;
4521+
this.condition = args.condition || undefined;
4522+
this.relativeFindMetadata = args.relativeFindMetadata || undefined;
4523+
this.relativeFindPercentThreshold = args.relativeFindPercentThreshold || undefined;
4524+
this.pageSize = args.pageSize || undefined;
4525+
this.latitude = args.latitude || undefined;
4526+
this.longitude = args.longitude || undefined;
4527+
this.radius = args.radius || undefined;
4528+
this.units = args.units || undefined;
4529+
this.degreePerPixel = args.degreePerPixel || undefined;
4530+
this.clusterGridSize = args.clusterGridSize || undefined;
45304531
};
45314532

45324533
GeoQuery.prototype = {

0 commit comments

Comments
 (0)