# abstract new Manager(baseManager, tableName, indexesopt, callbackopt)
Manager Classes in this context should do the bridge between the controllers and the services exposing only the necessary api to the controllers while encapsulating all business logic.
Manager Classes in this context should do the bridge between the controllers and the services exposing only the necessary api to the controllers while encapsulating all business logic.
All Manager Classes should be singletons.
This complete separation of concerns is very beneficial for 2 reasons:
- Allows for testing since there's no browser dependent code (i think) since the DSUStorage can be 'mocked'
- Allows for different controllers access different business logic when necessary (while benefiting from the singleton behaviour)
Manager SPECIFIC DataBase Access API (CRUD)
Methods:
- create - Must be overwritten by child classes
- getOne
- remove
- update - Should be overwritten by child classes
- getAll - with querying capabilities via DEFAULT_QUERY_OPTIONS type configuration
- getPage - paging and querying capabilities
Assumes only reads/writes to INFO_PATH with JSON parsing to object Otherwise the methods need to be overwritten by child classes.
Manager INDEPENDENT DataBase Access API
Methods:
- insertRecord
- getRecord
- deleteRecord
- updateRecord
- query - with querying capabilities via DEFAULT_QUERY_OPTIONS type configuration
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
baseManager |
BaseManager
|
the base manager to have access to the identity api |
|
tableName |
string
|
the default table name for this manager eg: MessageManager will write to the messages table |
|
indexes |
Array.<string>
|
<optional> |
a list of indexes to add to the table in the db upon initialization. requires a callback! |
callback |
function
|
<optional> |
optional callback for when the assurance that the table has already been indexed is required. Not used in this class. Child classes must implement if this functionality is required like:
if (this.indexes && callback){
super._indexTable(...this.indexes, (err) => {
if (err)
return self._err(`Could not update Indexes`, err, callback);
console.log(`Indexes for table ${self.tableName} updated`);
callback(undefined, self);
});
}
|