@@ -18,14 +18,18 @@ module.exports = function (app, options) {
1818 //
1919 // It would be good to have a discussion with the strongloop guys and see
2020 // if there is a better way this can be done.
21- options . debug ( 'Replace relationship remoting functions with custom implementations' )
21+ options . debug (
22+ 'Replace relationship remoting functions with custom implementations'
23+ )
2224 app . models ( ) . forEach ( function ( ctor ) {
2325 ctor . belongsToRemoting = belongsToRemoting
2426 ctor . hasOneRemoting = hasOneRemoting
2527 ctor . hasManyRemoting = hasManyRemoting
2628 ctor . scopeRemoting = scopeRemoting
2729 } )
28- options . debug ( '`belongsToRemoting`, `hasOneRemoting`, `hasManyRemoting`, `scopeRemoting` replaced' )
30+ options . debug (
31+ '`belongsToRemoting`, `hasOneRemoting`, `hasManyRemoting`, `scopeRemoting` replaced'
32+ )
2933
3034 // iterate through all remote methods and swap PUTs to PATCHs
3135 // as PUT is not supported by JSON API.
@@ -65,49 +69,59 @@ function convertNullToNotFoundError (toModelName, ctx, cb) {
6569
6670function belongsToRemoting ( relationName , relation , define ) {
6771 var fn = this . prototype [ relationName ]
68- var modelName = ( relation . modelTo && relation . modelTo . modelName ) || 'PersistedModel'
69- var pathName = ( relation . options . http && relation . options . http . path ) || relationName
72+ var modelName = ( relation . modelTo && relation . modelTo . modelName ) ||
73+ 'PersistedModel'
74+ var pathName = ( relation . options . http && relation . options . http . path ) ||
75+ relationName
7076
71- define ( '__get__' + relationName , {
72- isStatic : false ,
73- accessType : 'READ' ,
74- description : 'Fetches belongsTo relation ' + relationName + '.' ,
75- http : {
76- verb : 'get' ,
77- path : '/' + pathName
78- } ,
79- accepts : {
80- arg : 'refresh' ,
81- type : 'boolean' ,
77+ define (
78+ '__get__' + relationName ,
79+ {
80+ isStatic : false ,
81+ accessType : 'READ' ,
82+ description : 'Fetches belongsTo relation ' + relationName + '.' ,
8283 http : {
83- source : 'query'
84+ verb : 'get' ,
85+ path : '/' + pathName
86+ } ,
87+ accepts : {
88+ arg : 'refresh' ,
89+ type : 'boolean' ,
90+ http : {
91+ source : 'query'
92+ }
93+ } ,
94+ returns : {
95+ arg : relationName ,
96+ type : modelName ,
97+ root : true
8498 }
8599 } ,
86- returns : {
87- arg : relationName ,
88- type : modelName ,
89- root : true
90- }
91- } , fn )
100+ fn
101+ )
92102
93103 var findBelongsToRelationshipsFunc = function ( cb ) {
94104 this [ '__get__' + pathName ] ( cb )
95105 }
96106
97- define ( '__findRelationships__' + relationName , {
98- isStatic : false ,
99- accessType : 'READ' ,
100- description : 'Find relations for ' + relationName + '.' ,
101- http : {
102- verb : 'get' ,
103- path : '/relationships/' + pathName
107+ define (
108+ '__findRelationships__' + relationName ,
109+ {
110+ isStatic : false ,
111+ accessType : 'READ' ,
112+ description : 'Find relations for ' + relationName + '.' ,
113+ http : {
114+ verb : 'get' ,
115+ path : '/relationships/' + pathName
116+ } ,
117+ returns : {
118+ arg : 'result' ,
119+ type : modelName ,
120+ root : true
121+ }
104122 } ,
105- returns : {
106- arg : 'result' ,
107- type : modelName ,
108- root : true
109- }
110- } , findBelongsToRelationshipsFunc )
123+ findBelongsToRelationshipsFunc
124+ )
111125}
112126
113127/**
@@ -120,7 +134,8 @@ function belongsToRemoting (relationName, relation, define) {
120134 * @return {undefined }
121135 */
122136function hasOneRemoting ( relationName , relation , define ) {
123- var pathName = ( relation . options . http && relation . options . http . path ) || relationName
137+ var pathName = ( relation . options . http && relation . options . http . path ) ||
138+ relationName
124139 var toModelName = relation . modelTo . modelName
125140
126141 define ( '__get__' + relationName , {
@@ -149,20 +164,24 @@ function hasOneRemoting (relationName, relation, define) {
149164 this [ '__get__' + pathName ] ( cb )
150165 }
151166
152- define ( '__findRelationships__' + relationName , {
153- isStatic : false ,
154- accessType : 'READ' ,
155- description : 'Find relations for ' + relationName + '.' ,
156- http : {
157- verb : 'get' ,
158- path : '/relationships/' + pathName
167+ define (
168+ '__findRelationships__' + relationName ,
169+ {
170+ isStatic : false ,
171+ accessType : 'READ' ,
172+ description : 'Find relations for ' + relationName + '.' ,
173+ http : {
174+ verb : 'get' ,
175+ path : '/relationships/' + pathName
176+ } ,
177+ returns : {
178+ arg : 'result' ,
179+ type : toModelName ,
180+ root : true
181+ }
159182 } ,
160- returns : {
161- arg : 'result' ,
162- type : toModelName ,
163- root : true
164- }
165- } , findHasOneRelationshipsFunc )
183+ findHasOneRelationshipsFunc
184+ )
166185}
167186
168187/**
@@ -175,30 +194,35 @@ function hasOneRemoting (relationName, relation, define) {
175194 * @return {undefined }
176195 */
177196function hasManyRemoting ( relationName , relation , define ) {
178- var pathName = ( relation . options . http && relation . options . http . path ) || relationName
197+ var pathName = ( relation . options . http && relation . options . http . path ) ||
198+ relationName
179199 var toModelName = relation . modelTo . modelName
180200
181201 var findHasManyRelationshipsFunc = function ( cb ) {
182202 this [ '__get__' + pathName ] ( cb )
183203 }
184204
185- define ( '__findRelationships__' + relationName , {
186- isStatic : false ,
187- accessType : 'READ' ,
188- description : 'Find relations for ' + relationName + '.' ,
189- http : {
190- verb : 'get' ,
191- path : '/relationships/' + pathName
192- } ,
193- returns : {
194- arg : 'result' ,
195- type : toModelName ,
196- root : true
205+ define (
206+ '__findRelationships__' + relationName ,
207+ {
208+ isStatic : false ,
209+ accessType : 'READ' ,
210+ description : 'Find relations for ' + relationName + '.' ,
211+ http : {
212+ verb : 'get' ,
213+ path : '/relationships/' + pathName
214+ } ,
215+ returns : {
216+ arg : 'result' ,
217+ type : toModelName ,
218+ root : true
219+ } ,
220+ rest : {
221+ after : convertNullToNotFoundError . bind ( null , toModelName )
222+ }
197223 } ,
198- rest : {
199- after : convertNullToNotFoundError . bind ( null , toModelName )
200- }
201- } , findHasManyRelationshipsFunc )
224+ findHasManyRelationshipsFunc
225+ )
202226
203227 // var createRelationshipFunc = function (cb) {
204228 // TODO: implement this
@@ -302,7 +326,10 @@ function hasManyRemoting (relationName, relation, define) {
302326 * @return {undefined }
303327 */
304328function scopeRemoting ( scopeName , scope , define ) {
305- var pathName = ( scope . options && scope . options . http && scope . options . http . path ) || scopeName
329+ var pathName = ( scope . options &&
330+ scope . options . http &&
331+ scope . options . http . path ) ||
332+ scopeName
306333 var isStatic = scope . isStatic
307334 var toModelName = scope . modelTo . modelName
308335
0 commit comments