Skip to content

Commit b4af4f1

Browse files
author
Tom Kirkpatrick
committed
feat: add support for loopback 3.x
1 parent 94b24f7 commit b4af4f1

File tree

5 files changed

+54
-7
lines changed

5 files changed

+54
-7
lines changed

lib/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,23 @@ function addRemoteMethods(app) {
6363
return template
6464
}
6565

66-
// Define the remote method on the model
67-
Model.remoteMethod(fnNameRemote, {
66+
const fnSpecRemote = {
6867
description: `Generate template ${templateName}`,
69-
isStatic: true,
7068
accepts: [
7169
{ type: 'Object', arg: 'options', description: 'Overwrite values of template' },
7270
{ type: 'Object', arg: 'params', description: 'Pass parameters into the template method' },
7371
],
7472
returns: [ { type: 'Object', arg: 'result', root: true } ],
7573
http: { path, verb: 'get' },
76-
})
74+
}
75+
76+
// Support for loopback 2.x.
77+
if (app.loopback.version.startsWith(2)) {
78+
fnSpecRemote.isStatic = true
79+
}
80+
81+
// Define the remote method on the model
82+
Model.remoteMethod(fnNameRemote, fnSpecRemote)
7783

7884
// The remote method needs to be wrapped in a promise
7985
Model[fnNameRemote] = (options, params) => new Promise(resolve => resolve(Model[fnName](options, params)))
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+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "user",
3+
"base": "User",
4+
"options": {
5+
"idInjection": true,
6+
"validateUpsert": true,
7+
"forceId": false,
8+
"saltWorkFactor": 1,
9+
"replaceOnPUT": false
10+
},
11+
"validations": [],
12+
"relations": {
13+
"accessTokens": {
14+
"type": "hasMany",
15+
"model": "accessToken",
16+
"foreignKey": "userId",
17+
"options": {
18+
"disableInclude": true
19+
}
20+
}
21+
}
22+
}

test/test-server/server/config.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"host": "0.0.0.0",
44
"port": 3000,
55
"remoting": {
6-
"context": {
7-
"enableHttpContext": false
8-
},
6+
"context": false,
97
"rest": {
108
"normalizeHttpPath": false,
119
"xml": false

test/test-server/server/model-config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
"../../../lib/mixins"
1515
]
1616
},
17+
18+
"accessToken": {
19+
"dataSource": "db",
20+
"public": true
21+
},
22+
"user": {
23+
"dataSource": "db",
24+
"public": true
25+
},
1726
"ACL": {
1827
"dataSource": "db",
1928
"public": true

0 commit comments

Comments
 (0)