base-domain
Version:
simple module to help build Domain-Driven Design
116 lines (82 loc) • 2.19 kB
text/coffeescript
Promise = require('es6-promise').Promise
###*
interface of client accessing to resource.
Used in BaseRepository
LoopBackClient in loopback-promised package implements this interface.
see https://github.com/CureApp/loopback-promised
###
class ResourceClientInterface
###*
Create new instance of Model class, saved in database
###
create: (data = {}) ->
###*
Update or insert a model instance
The update will override any specified attributes in the request data object. It won’t remove existing ones unless the value is set to null.
###
upsert: (data = {}) ->
###*
Find object by ID.
###
findById: (id) ->
###*
Find all model instances that match filter specification.
###
find: (filter) ->
return Promise.resolve([{id: 'dummy', mock: true}])
###*
Find one model instance that matches filter specification. Same as find, but limited to one result
###
findOne: (filter) ->
###*
Destroy model instance with the specified ID.
###
destroyById: (id) ->
Promise.resolve({})
###*
Update set of attributes.
###
updateAttributes: (id, data) ->
###*
return Promise object as mock
###
mock: (arg1, arg2) ->
return Promise.resolve(id: 'dummy', mock: true, arg1: arg1, arg2: arg2)
module.exports = ResourceClientInterface