Skip to content

Commit e941d28

Browse files
author
Tom Kirkpatrick
committed
feat: update to loopback 3.x
BREAKING CHANGE: update to loopback 3.x
1 parent a187050 commit e941d28

18 files changed

+84
-57
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"lodash": "^4.17.4"
3939
},
4040
"peerDependencies": {
41-
"loopback": "^2.25.0",
41+
"loopback": "^3.4.0",
4242
"loopback-context": "^3.1.0",
4343
"cls-hooked": "^4.1.5"
4444
},
@@ -54,7 +54,7 @@
5454
"dirty-chai": "1.2.2",
5555
"eslint": "^3.19.0",
5656
"eslint-config-fullcube": "^2.0.2",
57-
"loopback": "^2.25.0",
57+
"loopback": "^3.4.0",
5858
"loopback-boot": "^2.24.0",
5959
"loopback-context": "^3.1.0",
6060
"cls-hooked": "^4.1.5",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "accessToken",
3+
"plural": "accessTokens",
4+
"base": "AccessToken",
5+
"relations": {
6+
"user": {
7+
"type": "belongsTo",
8+
"model": "user",
9+
"foreignKey": "userId"
10+
}
11+
}
12+
}

test/fixtures/simple-app/common/models/invoice.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/fixtures/simple-app/common/models/invoice.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "Invoice",
33
"base": "PersistedModel",
4-
"idInjection": true,
54
"options": {
6-
"validateUpsert": true
5+
"idInjection": true,
6+
"validateUpsert": true,
7+
"forceId": false,
8+
"replaceOnPUT": false
79
},
810
"properties": {
911
"storeId": {
@@ -59,14 +61,7 @@
5961
"principalType": "ROLE",
6062
"principalId": "$group:manager",
6163
"permission": "ALLOW",
62-
"property": "updateAttributes"
63-
},
64-
{
65-
"accessType": "WRITE",
66-
"principalType": "ROLE",
67-
"principalId": "$group:manager",
68-
"permission": "ALLOW",
69-
"property": "upsert"
64+
"property": ["patchOrCreate", "replaceOrCreate", "replaceById", "updateOrCreate", "updateAttributes", "patchAttributes"]
7065
},
7166
{
7267
"accessType": "*",

test/fixtures/simple-app/common/models/store.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/fixtures/simple-app/common/models/store.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "Store",
33
"base": "PersistedModel",
4-
"idInjection": true,
54
"options": {
6-
"validateUpsert": true
5+
"idInjection": true,
6+
"validateUpsert": true,
7+
"forceId": false,
8+
"replaceOnPUT": false
79
},
810
"properties": {
911
"id": {

test/fixtures/simple-app/common/models/team.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/fixtures/simple-app/common/models/team.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "Team",
33
"base": "PersistedModel",
4-
"idInjection": true,
54
"options": {
6-
"validateUpsert": true
5+
"idInjection": true,
6+
"validateUpsert": true,
7+
"forceId": false,
8+
"replaceOnPUT": false
79
},
810
"properties": {
911
"storeId": {

test/fixtures/simple-app/common/models/transaction.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/fixtures/simple-app/common/models/transaction.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "Transaction",
33
"base": "PersistedModel",
4-
"idInjection": true,
54
"options": {
6-
"validateUpsert": true
5+
"idInjection": true,
6+
"validateUpsert": true,
7+
"forceId": false,
8+
"replaceOnPUT": false
79
},
810
"properties": {
911
"storeId": {

test/fixtures/simple-app/common/models/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ module.exports = function userCustomizer(user) {
44
user.currentUser = function(cb) {
55
return process.nextTick(() => cb(null, user.getCurrentUser()))
66
}
7-
return user
7+
88
}

test/fixtures/simple-app/common/models/user.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"name": "user",
33
"base": "User",
4-
"idInjection": true,
54
"options": {
5+
"idInjection": true,
66
"validateUpsert": true,
7-
"saltWorkFactor": 1
7+
"forceId": false,
8+
"saltWorkFactor": 1,
9+
"replaceOnPUT": false
810
},
911
"mixins": {
1012
"GetCurrentUser": true
@@ -18,6 +20,14 @@
1820
},
1921
"validations": [],
2022
"relations": {
23+
"accessTokens": {
24+
"type": "hasMany",
25+
"model": "accessToken",
26+
"foreignKey": "userId",
27+
"options": {
28+
"disableInclude": true
29+
}
30+
},
2131
"stores": {
2232
"type": "hasMany",
2333
"model": "Store",
@@ -55,7 +65,6 @@
5565
"methods": {
5666
"currentUser": {
5767
"description": "Get the current user.",
58-
"isStatic": true,
5968
"http": {
6069
"path": "/currentUser",
6170
"verb": "get"

test/fixtures/simple-app/server/config.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
"extended": true,
1717
"limit": "100kb"
1818
},
19-
"cors": false,
20-
"errorHandler": {
21-
"disableStackTrace": false
22-
}
19+
"cors": false
2320
},
2421
"legacyExplorer": false,
2522
"logoutSessionsOnSensitiveChanges": true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"final:after": {
3+
"strong-error-handler": {
4+
"params": {
5+
"debug": true,
6+
"log": true
7+
}
8+
}
9+
}
10+
}

test/fixtures/simple-app/server/middleware.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
{
2+
"initial:before": {
3+
"loopback#token": {
4+
"params": {
5+
"model": "accessToken"
6+
}
7+
}
8+
},
29
"initial": {
310
"loopback-context#per-request": {
411
"params": {
@@ -7,9 +14,7 @@
714
}
815
},
916
"session": {},
10-
"auth": {
11-
"loopback#token": {}
12-
},
17+
"auth": {},
1318
"parse": {},
1419
"routes": {
1520
"loopback#rest": {
@@ -23,6 +28,6 @@
2328
"loopback#urlNotFound": {}
2429
},
2530
"final:after": {
26-
"loopback#errorHandler": {}
31+
"strong-error-handler": {}
2732
}
2833
}

test/fixtures/simple-app/server/model-config.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,25 @@
1414
"../../../../lib/mixins"
1515
]
1616
},
17-
"AccessToken": {
17+
18+
"accessToken": {
1819
"dataSource": "db",
1920
"public": true
2021
},
21-
"ACL": {
22+
"user": {
2223
"dataSource": "db",
2324
"public": true
2425
},
25-
"RoleMapping": {
26+
27+
"ACL": {
2628
"dataSource": "db",
2729
"public": true
2830
},
29-
"Role": {
31+
"RoleMapping": {
3032
"dataSource": "db",
3133
"public": true
3234
},
33-
"user": {
35+
"Role": {
3436
"dataSource": "db",
3537
"public": true
3638
},

test/fixtures/simple-app/server/server.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ const loopback = require('loopback')
66
const boot = require('loopback-boot')
77
const app = loopback()
88

9-
global.Promise = require('bluebird')
10-
119
app.start = function() {
1210
// start the web server
1311
return app.listen(function() {

test/mixin-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ function json(verb, url, data) {
2121
.expect('Content-Type', /json/)
2222
}
2323

24+
/**
25+
* Initialise the application for the test suite.
26+
*/
27+
before(done => {
28+
function finishBoot() {
29+
return done()
30+
}
31+
if (app.booting) {
32+
return app.once('booted', finishBoot)
33+
}
34+
return finishBoot()
35+
})
36+
2437
describe('Current User Mixin.', function() {
2538
describe('Smoke test', function() {
2639
it('should add a getCurrentUser model method', function() {

0 commit comments

Comments
 (0)