Show:
Module: model
Parent Module: mixins

mixin in ORM model

Methods

_filterParams
(
  • params
)
private

filter request params

Parameters:

Returns:

Object filtered params

createRecord
(
  • init
)

create new model with init options and model property

Parameters:

Returns:

Object current model

deleteRecord
(
  • model
  • data
)

delete the record from backend

Parameters:

  • model Object
  • data Object

    passed to backend server as extra params

Returns:

Promise

deleteSerializer
(
  • data
)

serializer for delete

Parameters:

  • data Object

    response data from backend

Returns:

serializer data

find
(
  • params
)

find the records from backend according to params

Parameters:

Returns:

Promise

findOne
(
  • id
  • data
)

find only one according to primary id

Parameters:

  • id String

    primary key

  • data Object

    query parameter append to url

Returns:

Promise

findOneSerializer
(
  • data
)

serializer for findOne method

Parameters:

  • data Object

    response data from backend

Returns:

serializer data

findSerializer
(
  • data
)

find serializer

Parameters:

  • data Object

    response data from backend

Returns:

serializer data

save
(
  • model
)
Promise

save the record to backend when create or update object

Parameters:

  • model Object

    model needed to save

Returns:

saveSerializer
(
  • data
)

serializer for save method

Parameters:

  • data Object

    response data from backend

Returns:

serializer data

urlForDelete
(
  • id
)

url for delete method request, use this method to custome delete url

Parameters:

  • id Object

    object primary key

Returns:

String

urlForFind ()

url for find method request, use this method to custome find url

Returns:

String

urlForFindOne ()

url for findOne method request, use this method to custome findOne url

Returns:

String

urlForSave
(
  • id
)

url for save method request, use this method to custome create and update url

Parameters:

  • id Object

    object primary key

Returns:

String

Properties

api

String

make api with host, namespace, url

displayModel

Object

The object is for extract response data {user: [], comment:[], avatar: {}}

Default: null

host

String

The api host, default is current host

Default: ""

namespace

String

The api namespace like /v1 /v2

Default: ""

primaryKey

String

The model object primary key

Default: "_id"

rootKey

String

The response data business logic root key like: {'code': 0, 'resp':{'user':[]}, 'msg':''}, the resp is is the rootKey

Default: ""

url

String

The api url. If rootURL ends with slash , the url should not starts with slash

Default: ""