chore: Refactor v2 folder and class structure + Adding Company App (dummy)

This commit is contained in:
Josepablo C
2024-08-07 00:59:50 -06:00
parent f8d41db04d
commit 288fdc10a7
24 changed files with 614 additions and 190 deletions

View File

@@ -0,0 +1,48 @@
'use strict';
const Application = require('../Domain');
function dummy_middleware( req, res, next ){
Application.trigger_example_event( {
example : "This is an example of event data"
} )
return res.status(500).send({ error:"Not implemented yet" });
}
function AppInit(){
Application.init();
}
module.exports = {
AppInit,
hooks : {
before: {
/**Array of middleware functions*/
all : [],
del : [],
get : [],
patch : [],
post : [],
put : []
},
after: {
/**Array of middleware functions*/
all : [],
del : [],
get : [],
patch : [],
post : [],
put : []
},
custom: {
/**Array of objects like { endpoint, middleware }*/
all : [ { "/test" : dummy_middleware } ],
del : [],
get : [],
patch : [],
post : [],
put : []
}
}
};

View File

@@ -0,0 +1,13 @@
'use strict';
const { hooks, AppInit } = require( './hooks' );
const GenericController = require('../../Lib');
class Company extends GenericController {
init(){
super.init();
AppInit();
}
}
module.exports = new Company( hooks );

View File

@@ -0,0 +1,34 @@
'use strict';
const Repository = require('../Repository');
const Interfaces = require('../Interfaces');
class Company {
constructor(){
this.Events = {
/** Event_Id : callback */
"Example" : this.event_handler_example
};
}
init(){
/// Setup application events
const Events = this.Events;
/// Setup application events
for ( const [event, callback] of Object.entries( Events ) ) {
const event_id = Interfaces.ModuleName + event
Interfaces.registerEvent( event_id , callback );
}
}
trigger_example_event( data ){
Interfaces.publishEvent( "Example", data );
}
event_handler_example( data ){
console.log( "CompanyDomain event" );
console.log( data );
}
};
module.exports = new Company();

View File

@@ -0,0 +1,27 @@
'use strict';
const ModuleName = "App:Company:";
const SharedResources = require('../../../Shared/Resources');
function registerEvent( event_id , callback ){
const EventBus = SharedResources.get("SysS:EventManager");
console.log(`Loading event ${event_id}`);
EventBus.addEvent( event_id , callback );
}
function publishEvent( event , data = null ){
const EventBus = SharedResources.get("SysS:EventManager");
const AppEventDomain = ModuleName;
const event_id = AppEventDomain + event;
console.log( event_id );
EventBus.publishEvent( event_id , data );
}
module.exports = {
ModuleName,
registerEvent,
publishEvent
};

View File

@@ -0,0 +1,3 @@
'use strict';
module.exports = {};

View File

@@ -0,0 +1,5 @@
'use strict';
const SpecificModelRepository = require('./Objection');
module.exports = SpecificModelRepository;