Skip to content

Commit

Permalink
refactor: move not a part of FHIR model to staticModel folder
Browse files Browse the repository at this point in the history
feat: change get mongodb collection method

Use function to read all js file with input path.
  • Loading branch information
Chinlinlee committed Oct 24, 2021
1 parent 2a60bcc commit 59c0153
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions models/mongodb/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,20 @@ module.exports = exports = function(config) {
db.once('open', function() {
console.log("we're connected!");
});

fs.readdirSync(__dirname + '/model')
.filter((file) => (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js'))
.forEach((file) => {
const moduleName = file.split('.')[0];
console.log('moduleName :: ', moduleName);
console.log('path : ', __dirname + '/model')
collection[moduleName] = require(__dirname + '/model/' + moduleName)(mongoose);
});
getCollections('/model', collection);
getCollections('/staticModel', collection);

return collection;
};
};

function getCollections (dirname, collectionObj) {
let jsFilesInDir = fs.readdirSync(__dirname + dirname)
.filter((file) => (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js'))
for (let file of jsFilesInDir) {
const moduleName = file.split('.')[0];
console.log('moduleName :: ', moduleName);
console.log('path : ', __dirname + dirname)
collectionObj[moduleName] = require(__dirname + dirname +'/' + moduleName)(mongoose);
}

}
File renamed without changes.
File renamed without changes.

0 comments on commit 59c0153

Please sign in to comment.