Skip to content

Commit

Permalink
fix(global): extends class with tabstractobject and fix all console s…
Browse files Browse the repository at this point in the history
…tatement
  • Loading branch information
Itee committed Jul 2, 2021
1 parent efe41ec commit 8551dbd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion configs/eslint.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function CreateEslintConfiguration () {
'no-multiple-empty-lines': [ 1, { 'max': 2 } ],
'no-mixed-spaces-and-tabs': 'off',
'mocha/no-exclusive-tests': 'error',
'no-console': 'warn',
'no-console': 'error',
'no-multi-spaces': [
'error', {
exceptions: {
Expand Down
2 changes: 1 addition & 1 deletion sources/converters/TAbstractConverterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TAbstractConverterManager extends TAbstractResponder {

_fileConversionProgressCallback ( response, progress ) {

console.log( progress )
this.logger.log( progress )

}

Expand Down
14 changes: 7 additions & 7 deletions sources/databases/TAbstractDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class TAbstractDatabase extends TAbstractObject {
if ( this._registerPackagePlugin( name, config ) ) { return }
if ( this._registerLocalPlugin( name, config ) ) { return }

console.error( `Unable to register the plugin ${ name } the package or local folder doesn't seem to exist ! Skip it.` )
this.logger.error( `Unable to register the plugin ${ name } the package or local folder doesn't seem to exist ! Skip it.` )

}

Expand All @@ -168,23 +168,23 @@ class TAbstractDatabase extends TAbstractObject {
const plugin = require( name )
if ( plugin instanceof TAbstractDatabasePlugin ) {

console.log( `Use ${ name } plugin from node_modules` )
this.logger.log( `Use ${ name } plugin from node_modules` )
plugin.__dirname = path.dirname( require.resolve( name ) )
plugin.registerTo( this.driver, this.application, this.router )

success = true

} else {

console.error( `The plugin ${ name } doesn't seem to be an instance of an extended class from TAbstractDatabasePlugin ! Skip it.` )
this.logger.error( `The plugin ${ name } doesn't seem to be an instance of an extended class from TAbstractDatabasePlugin ! Skip it.` )

}

} catch ( error ) {

if ( !error.code || error.code !== 'MODULE_NOT_FOUND' ) {

console.error( error )
this.logger.error( error )

}

Expand All @@ -206,21 +206,21 @@ class TAbstractDatabase extends TAbstractObject {

if ( plugin instanceof TAbstractDatabasePlugin ) {

console.log( `Use ${ name } plugin from local folder` )
this.logger.log( `Use ${ name } plugin from local folder` )
plugin.__dirname = path.dirname( require.resolve( localPluginPath ) )
plugin.registerTo( this.driver, this.application, this.router )

success = true

} else {

console.error( `The plugin ${ name } doesn't seem to be an instance of an extended class from TAbstractDatabasePlugin ! Skip it.` )
this.logger.error( `The plugin ${ name } doesn't seem to be an instance of an extended class from TAbstractDatabasePlugin ! Skip it.` )

}

} catch ( error ) {

console.error( error )
this.logger.error( error )

}

Expand Down
3 changes: 2 additions & 1 deletion sources/databases/TAbstractResponder.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import {
isObject,
isString
} from 'itee-validators'
import { TAbstractObject } from 'itee-core'
import { UnknownError } from '../messages/http/UnknownError'

/**
* @class
* @classdesc The TAbstractResponder is the base class for all derived database controller that require to send a response to client.
* It allow to send preformatted response in function of database query result.
*/
class TAbstractResponder {
class TAbstractResponder extends TAbstractObject {

/**
* Normalize errors that can be in different format like single string, object, array of string, or array of object.
Expand Down
9 changes: 6 additions & 3 deletions sources/plugins/TAbstractDatabasePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
isNull,
isUndefined
} from 'itee-validators'
import { TAbstractObject } from 'itee-core'

class TAbstractDatabasePlugin {
class TAbstractDatabasePlugin extends TAbstractObject {

constructor ( parameters = {} ) {

Expand All @@ -21,6 +22,8 @@ class TAbstractDatabasePlugin {
...parameters
}

super(_parameters)

this.controllers = _parameters.controllers
this.descriptors = _parameters.descriptors

Expand Down Expand Up @@ -64,7 +67,7 @@ class TAbstractDatabasePlugin {
const controller = new ControllerClass( { driver: Driver, ...descriptor.controller.options } )
const router = Router( { mergeParams: true } )

console.log( `\tAdd controller for base route: ${ descriptor.route }` )
this.logger.log( `\tAdd controller for base route: ${ descriptor.route }` )
Application.use( descriptor.route, TAbstractDatabasePlugin._populateRouter( router, controller, descriptor.controller.can ) )

}
Expand All @@ -77,7 +80,7 @@ class TAbstractDatabasePlugin {

const action = can[ _do ]

console.log( `\t\tMap route ${ action.over } on (${ action.on }) to ${ controller.constructor.name }.${ _do } method.` )
this.logger.log( `\t\tMap route ${ action.over } on (${ action.on }) to ${ controller.constructor.name }.${ _do } method.` )
router[ action.on ]( action.over, controller[ _do ].bind( controller ) )

}
Expand Down

0 comments on commit 8551dbd

Please sign in to comment.