chore: Refactor v2 folder and class structure + Adding Company App (dummy)
This commit is contained in:
48
v2/server/src/Apps/Company/Controller/hooks.js
Normal file
48
v2/server/src/Apps/Company/Controller/hooks.js
Normal 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 : []
|
||||
}
|
||||
}
|
||||
};
|
||||
13
v2/server/src/Apps/Company/Controller/index.js
Normal file
13
v2/server/src/Apps/Company/Controller/index.js
Normal 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 );
|
||||
34
v2/server/src/Apps/Company/Domain/index.js
Normal file
34
v2/server/src/Apps/Company/Domain/index.js
Normal 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();
|
||||
27
v2/server/src/Apps/Company/Interfaces/index.js
Normal file
27
v2/server/src/Apps/Company/Interfaces/index.js
Normal 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
|
||||
};
|
||||
3
v2/server/src/Apps/Company/Repository/Objection/index.js
Normal file
3
v2/server/src/Apps/Company/Repository/Objection/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {};
|
||||
5
v2/server/src/Apps/Company/Repository/index.js
Normal file
5
v2/server/src/Apps/Company/Repository/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const SpecificModelRepository = require('./Objection');
|
||||
|
||||
module.exports = SpecificModelRepository;
|
||||
Reference in New Issue
Block a user