API Docs for:
Show:

BaseRepository Class

Base repository class of DDD pattern. Responsible for perpetuation of models. BaseRepository has a client, which access to data resource (RDB, NoSQL, memory, etc...)

the parent "Base" class just simply gives this.facade property

Methods

appendTimeStamp

(
  • data
  • isUpdate
)
Object protected

add createdAt, updatedAt to given data

  • createdAt will not be overriden if already set.
  • updatedAt will be overriden for each time

Parameters:

  • data Object
  • isUpdate Boolean

    true when updating

Returns:

Object:

data

createFromQueryResults

(
  • params
  • objs
  • [options]
)
Array(BaseModel) protected

Create model instances from query results

Parameters:

  • params Object
  • objs Array(Object)
  • [options] Object optional

Returns:

Array(BaseModel):

models

createFromResult

(
  • obj
  • [options]
)
BaseModel protected

Create model instance from result from client

Parameters:

  • obj Object
  • [options] Object optional

Returns:

BaseModel:

model

delete

(
  • entity
  • [options]
)
Boolean | Promise(Boolean) public

Destroy the given entity (which must have "id" value)

Parameters:

Returns:

Boolean | Promise(Boolean):

isDeleted

deprecated

(
  • methodName
  • message
)
Error protected

Show indication message of deprecated method

Parameters:

  • methodName String
  • message String

Returns:

Error:

error

(
  • reason
  • [message]
)
Error

create instance of DomainError

Parameters:

  • reason String

    reason of the error

  • [message] String optional

Returns:

Error:

get

(
  • id
  • [options]
)
Entity | Promise(Entity) public

get entity by id.

Parameters:

Returns:

Entity | Promise(Entity):

entity

getAll

() Array(Entity) | Promise(Array(Entity))

get all entities

Returns:

Array(Entity) | Promise(Array(Entity)):

array of entities

getById

(
  • id
  • [options]
)
Entity | Promise(Entity) public

alias for get()

Parameters:

Returns:

Entity | Promise(Entity):

entity

getByIds

(
  • ids
  • [options]
)
Array(Entity) | Promise(Array(Entity)) public

get entities by id.

Parameters:

Returns:

Array(Entity) | Promise(Array(Entity)):

entities

getDiff

(
  • entity
  • [options]
)
Object | Promise(Object) public

get diff from perpetuation layer

Parameters:

Returns:

Object | Promise(Object):

diff

getFacade

() Facade deprecated

Inherited from Base: /home/ubuntu/base-domain/src/lib/base.coffee:81

Deprecated: just use this.facade

Get facade

Returns:

getModelClass

() Class

get model class this factory handles

Returns:

Class:

getModule

() BaseModule

Get module which this class belongs to

Returns:

getParent

() Function

get parent class

Returns:

Function:

query

(
  • [params]
  • [options]
)
Array(Entity) | Promise(Array(Entity)) public

Find all model instances that match params

Parameters:

  • [params] Object optional

    query parameters

  • [options] Object optional

Returns:

Array(Entity) | Promise(Array(Entity)):

array of entities

save

(
  • entity
  • [options]
)
Entity | Promise(Entity) public

Update or insert a model instance

Parameters:

Returns:

Entity | Promise(Entity):

entity (the same instance from input, if entity given,)

setRoot

() protected

singleQuery

(
  • [params]
  • [options]
)
Entity | Promise(Entity) public

Find one model instance that matches params, Same as query, but limited to one result

Parameters:

  • [params] Object optional

    query parameters

  • [options] Object optional

Returns:

Entity | Promise(Entity):

entity

update

(
  • id
  • data
  • [options]
)
Entity | Promise(Entity) public

Update set of attributes.

Parameters:

  • id String | Number

    id of the entity to update

  • data Object

    key-value pair to update (notice: this must not be instance of Entity)

  • [options] Object optional

Returns:

Entity | Promise(Entity):

updated entity

updateProps

(
  • entity
  • data
  • [options]
)
Promise(Object) | Object public

Update set of attributes and returns newly-updated props (other than props)

Parameters:

  • entity Entity
  • data Object

    key-value pair to update (notice: this must not be instance of Entity)

  • [options] Object optional

Returns:

Promise(Object) | Object:

updated props

Properties

client

ResourceClientInterface protected

client accessing to data resource (RDB, NoSQL, memory, etc...)

mock object is input by default. Extenders must set this property to achieve perpetuation

modelName

String protected static

model name to handle