CategoryRepository
CategoryRepository
is the base class that every repository inherit from.
Extends
AbstractRepository
class CategoryReporitory extends AbstractRepository
Static Methods
::getName
static getName(): string
Returns:
Type: constant ("Category" :string)
Overwritten Methods
findBy
findBy(filters: Object<string, *>): Array<Category>
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
filters | Object<string, *> | Yes | - | An object with entity property as key and associated filter function as value. See search doc |
Returns:
Type: Array<Category>
findOneBy
findOneBy(filters: Object<string, *>): Category|null
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
filters | Object<string, *> | Yes | - | An object with entity property as key and associated filter function as value. See search doc |
Returns:
Type: Category|null
isValid
isValid(entity: Category): boolean
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
entity | Category | Yes | - |
Returns:
Type: boolean
get
get(id: int|symbol|Category|Reference<Category>|null): Category|null
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
id | int | symbol | Category | Reference<Category> | null | Yes | - |
Returns:
Type: Category|null
getAll
getAll(): Array<Category>
Returns:
Type: Array<Category>
getList
getList(ids: Array<int|symbol|Category|Reference<Category>|null>): Array<Category|null>
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
ids | Array<int | symbol | Category | Reference<Category> | null> | Yes | - |
Returns:
Type: Array<Category|null>
persist
persist(entity: Category): void
Create / Update an entity
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
entity | Category | Yes | - |
Returns:
Type: void
remove
remove(entity: Category|Reference<Category>|symbol|int): void
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
entity | Array<int | symbol | Category | Reference<Category> | Yes | - |
Returns:
Type: void
validate
validate(entity: Category): Map<string,string>
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
entity | Category | Yes | - |
Returns:
A Map of invalid properties associated to error message
Type: Map<string,string>
validateProperty
validateProperty(entity: Category, property: string): string|null
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
entity | Category | Yes | - | |
property | string | Yes | - |
Returns:
The error message or null if it's valid
Type: string|null
Inherited Methods
isLoaded
isLoaded(): boolean
Returns:
Type: boolean
isLoading
isLoading(): boolean
Returns:
Type: boolean
load
async load(fallbackOnCache: boolean = true): Promise<void, Error>
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
fallbackOnCache | boolean | No | true | If request to API fail, then it will fallback to CacheManager if this parameter is true |
Returns:
Type: Promise<void, Error>
loadFromCache
async loadFromCache(allowOutdated: boolean = false): Promise<void, Error>
Parameters:
Name | Type | Required | Default | Description |
---|---|---|---|---|
allowOutdated | boolean | No | false | If the cache is not up-to-date, it will reject the loading. See Offline - Cache First |
Returns:
Type: Promise<void, Error>
Overwritten Events
CREATE
EventDispatcher.subscribe(repository, REPOSITORY_EVENTS.CREATE, listener)
Create event is fired when persisting a new entity (i.e. id is null).
The listener will receive the following parameters
Listener Parameters:
Name | Type | Description |
---|---|---|
entity | Category |
UPDATE
EventDispatcher.subscribe(repository, REPOSITORY_EVENTS.UPDATE, listener)
Create event is fired when persisting an existing entity.
The listener will receive the following parameters
Listener Parameters:
Name | Type | Description |
---|---|---|
data | object | |
data.current | Category | A read-only copy of the newly updated entity |
data.previous | Category | A read-only copy of the previous entity |
data.changes | string[] | An array containing all updated properties |
REMOVE
EventDispatcher.subscribe(repository, REPOSITORY_EVENTS.REMOVE, listener)
Create event is fired when removing entity.
The listener will receive the following parameters
Listener Parameters:
Name | Type | Description |
---|---|---|
entity | Category |
IDENTIFIER_WILL_CHANGE
EventDispatcher.subscribe(repository, REPOSITORY_EVENTS.IDENTIFIER_WILL_CHANGE, listener)
This event is fired during flush BEFORE the object identifier is updated according to the remote server.
Usage: When a new entity is created, the EntityManager will assign a Symbol() as id. When flushing, the entity is saved on the remote server which will send it's real id.
The listener will receive the following parameters
Listener Parameters:
Name | Type | Description |
---|---|---|
data | Array<int | symbol> | An array of size 2 elements [first, second] respectively the next and current id |
data[0] | int | symbol | the new id |
data[1] | int | symbol | the current id |
IDENTIFIER_DID_CHANGE
EventDispatcher.subscribe(repository, REPOSITORY_EVENTS.IDENTIFIER_DID_CHANGE, listener)
This event is fired during flush AFTER the object identifier is updated according to the remote server.
Usage: When a new entity is created, the EntityManager will assign a Symbol() as id. When flushing, the entity is saved on the remote server which will send it's real id.
The listener will receive the following parameters
Listener Parameters:
Name | Type | Description |
---|---|---|
data | Array<int | symbol> | An array of size 2 elements [first, second] respectively the current and previous id |
data[0] | int | symbol | the current id |
data[1] | int | symbol | the previous id |