Skip to content

Commit

Permalink
feat: handle nested initailization function
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Aug 28, 2024
1 parent 20c47b6 commit c46b449
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,22 @@ class CoCreateLazyLoader {
throw new Error(`Missing ${name} key in organization apis object`);

// ToDo: if data.endpoint service not required as endpoint will be used
const service = require(config.path);
let instance
if (config.initialize)
instance = new service[config.initialize](key);
else
instance = new service(key);
let instance = require(config.path);

if (config.initialize) {
const initialize = config.initialize.split('.');

// Traverse the nested structure to reach the correct constructor
for (let i = 0; i < initialize.length; i++) {
if (instance[initialize[i]]) {
instance = instance[initialize[i]];
} else {
throw new Error(`Service path ${config.initialize} is incorrect at ${initialize[i]}`);
}
}
}

instance = new instance(key);

let params = [], mainParam = false
for (let i = 0; true; i++) {
Expand Down

0 comments on commit c46b449

Please sign in to comment.