|
| 1 | +const mongoMiddleware = require('./mwMongo.js') |
| 2 | +const sqlMiddleware = require('./mwSQL.js') |
| 3 | + |
| 4 | +const chronos = {} |
| 5 | + chronos.microHealth = (microserviceName, databaseType, userOwnedDB) => { |
| 6 | + microserviceName.toLowerCase(); |
| 7 | + databaseType.toLowerCase(); |
| 8 | + |
| 9 | + if (!microserviceName || !databaseType || !userOwnedDB) { |
| 10 | + throw new Error( |
| 11 | + "Please verify that you have provided all three required parameters" |
| 12 | + ); |
| 13 | + } |
| 14 | + |
| 15 | + if ( |
| 16 | + typeof microserviceName !== "string" || |
| 17 | + typeof databaseType !== "string" || |
| 18 | + typeof userOwnedDB !== "string" |
| 19 | + ) { |
| 20 | + throw new Error( |
| 21 | + "Please verify that the parameters you entered are all strings" |
| 22 | + ); |
| 23 | + } |
| 24 | + |
| 25 | + if (databaseType === "mongo" || databaseType === "mongodb") { |
| 26 | + return mongoMiddleware.microHealth(userOwnedDB, microserviceName); |
| 27 | + } else if (databaseType === "sql" || databaseType === "postgresql") { |
| 28 | + return sqlMiddleware.microHealth(userOwnedDB, microserviceName); |
| 29 | + } else { |
| 30 | + throw new Error ( |
| 31 | + 'Chronos currently only supports Mongo and SQL/PostgresQL databases. Please enter "mongo" or "sql' |
| 32 | + ); |
| 33 | + } |
| 34 | + }, |
| 35 | + chronos.microCom = (microserviceName, databaseType, userOwnedDB, req, res, next) => { |
| 36 | + microserviceName.toLowerCase(); |
| 37 | + databaseType.toLowerCase(); |
| 38 | + |
| 39 | + if (!microserviceName || !databaseType || !userOwnedDB) { |
| 40 | + throw new Error( |
| 41 | + "Please verify that you have provided all three required parameters" |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + if ( |
| 46 | + typeof microserviceName !== "string" || |
| 47 | + typeof databaseType !== "string" || |
| 48 | + typeof userOwnedDB !== "string" |
| 49 | + ) { |
| 50 | + throw new Error( |
| 51 | + "Please verify that the parameters you entered are all strings" |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + if (databaseType === "mongo" || databaseType === "mongodb") { |
| 56 | + return mongoMiddleware.microCom(userOwnedDB, microserviceName); |
| 57 | + } else if (databaseType === "sql" || databaseType === "postgresql") { |
| 58 | + return sqlMiddleware.microCom(userOwnedDB, microserviceName); |
| 59 | + } else { |
| 60 | + throw new Error( |
| 61 | + 'Chronos currently only supports Mongo and SQL/PostgresQL databases. Please enter "mongo" or "sql' |
| 62 | + ); |
| 63 | + } |
| 64 | +}; |
| 65 | + |
| 66 | + |
| 67 | +module.exports = chronos; |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
0 commit comments