1- import _ from 'lodash' ;
1+ import forEach from 'lodash/forEach' ;
2+ import has from 'lodash/has' ;
3+ import map from 'lodash/map' ;
4+ import merge from 'lodash/merge' ;
25import Context from '../common/context' ;
36import { ModuleConfig , ModelConfig } from '../support/interfaces' ;
47
@@ -8,7 +11,7 @@ export default class Action {
811 * @param {object } model
912 */
1013 static transformModule ( module ) {
11- return _ . merge ( { } , ModuleConfig , module ) ;
14+ return merge ( { } , ModuleConfig , module ) ;
1215 }
1316
1417 /**
@@ -17,22 +20,22 @@ export default class Action {
1720 */
1821 static transformModel ( model ) {
1922 const context = Context . getInstance ( ) ;
20- ModelConfig . http = _ . merge ( { } , ModelConfig . http , context . options . http ) ;
21- model . methodConf = _ . merge ( { } , ModelConfig , model . methodConf ) ;
23+ ModelConfig . http = merge ( { } , ModelConfig . http , context . options . http ) ;
24+ model . methodConf = merge ( { } , ModelConfig , model . methodConf ) ;
2225 model . methodConf . http . url = ( model . methodConf . http . url === '/' ) ? `/${ model . entity } ` : model . methodConf . http . url ;
2326
2427 /**
2528 * Add Model Interface to each model
2629 */
2730 model . getFields = ( ) => {
2831 if ( ! model . cachedFields ) {
29- model . cachedFields = _ . merge ( { } , {
32+ model . cachedFields = merge ( { } , {
3033 $id : model . attr ( undefined ) ,
3134 $isUpdating : model . boolean ( false ) ,
3235 $updateErrors : model . attr ( [ ] ) ,
3336 $isDeleting : model . boolean ( false ) ,
3437 $deleteErrors : model . attr ( [ ] ) ,
35- } , model . fields ( ) )
38+ } , model . fields ( ) ) ;
3639 }
3740
3841 return model . cachedFields ;
@@ -47,14 +50,14 @@ export default class Action {
4750 * @param {object } model
4851 * @param {object } config
4952 */
50- static transformParams ( type , model , config = { } ) {
53+ static transformParams ( type , model , config = { } ) {
5154 let endpoint = `${ model . methodConf . http . url } ${ model . methodConf . methods [ type ] . http . url } ` ;
52- let params = _ . map ( endpoint . match ( / ( \/ ? ) ( \: ) ( [ A - z ] * ) / gm) , ( param ) => { return param . replace ( '/' , '' ) } )
55+ const params = map ( endpoint . match ( / ( \/ ? ) ( \: ) ( [ A - z ] * ) / gm) , param => param . replace ( '/' , '' ) ) ;
5356
54- _ . forEach ( params , ( param ) => {
55- const paramValue = _ . has ( config . params , param . replace ( ':' , '' ) ) ? config . params [ param . replace ( ':' , '' ) ] : ''
56- endpoint = endpoint . replace ( param , paramValue ) . replace ( '//' , '/' )
57- } )
57+ forEach ( params , ( param ) => {
58+ const paramValue = has ( config . params , param . replace ( ':' , '' ) ) ? config . params [ param . replace ( ':' , '' ) ] : '' ;
59+ endpoint = endpoint . replace ( param , paramValue ) . replace ( '//' , '/' ) ;
60+ } ) ;
5861 if ( config . query ) endpoint += `?${ Object . keys ( config . query ) . map ( k => `${ encodeURIComponent ( k ) } =${ encodeURIComponent ( config . query [ k ] ) } ` ) . join ( '&' ) } ` ;
5962 return endpoint ;
6063 }
0 commit comments