-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 92d5bd8
Showing
10 changed files
with
1,577 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Archivos de configuración | ||
.env | ||
|
||
# Logs | ||
logs | ||
**/*.log | ||
**/*.log* | ||
|
||
|
||
# Dependency directories | ||
node_modules | ||
typings | ||
typings/* | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function env(key, _default, type = 's') { | ||
if (!!process.env[key] === false) { | ||
return _default; | ||
} | ||
const value = process.env[key]; | ||
switch (type) { | ||
case 'b': | ||
return value.toLowerCase() === 'true'; | ||
case 'n': | ||
return parseInt(value, 10); | ||
default: | ||
return value; | ||
} | ||
} | ||
|
||
|
||
module.exports = { | ||
api: { | ||
url: env('API_URL', 'http://localhost:3004/api/'), | ||
}, | ||
db: { | ||
sqlserver: { | ||
server: env('SQLSERVER_SERVER', '172.16.1.79'), | ||
database: env('SQLSERVER_DB', 'Hospital'), | ||
user: env('SQLSERVER_USER', 'danievas'), | ||
password: env('SQLSERVER_PASS', 'PeThiSha'), | ||
}, | ||
mongo: { | ||
url: env('MONGO_HOST', 'mongodb://localhost:27017'), | ||
database: env('MONGO_DB', 'rrhh_testing') | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const config = require('./config'); | ||
const logger = require('./logger').logger; | ||
const sqlClient = require('mssql'); | ||
const mongoose = require('mongoose'); | ||
|
||
|
||
// SQLServer Config | ||
const sqlConfig = { | ||
user: config.db.sqlserver.user, | ||
password: config.db.sqlserver.password, | ||
server: config.db.sqlserver.server, | ||
database: config.db.sqlserver.database, | ||
parseJSON: true, | ||
requestTimeout:60000, | ||
connectionTimeout:60000, | ||
pool: { | ||
max: 10, | ||
min: 0, | ||
idleTimeoutMillis: 30000 | ||
} | ||
} | ||
|
||
const sqlServerPool = new sqlClient.ConnectionPool(sqlConfig); | ||
|
||
sqlServerPool.on('error', err => { | ||
logger.error('SQLServer Error' + err); | ||
}) | ||
|
||
|
||
//MongoDB Config | ||
const mongoConfig = { | ||
url: config.db.mongo.url, | ||
database: config.db.mongo.database | ||
} | ||
|
||
mongoose.Promise = Promise | ||
|
||
mongoose.connection.on('connected', () => { | ||
logger.debug('MongoDB Connection Established') | ||
}) | ||
|
||
mongoose.connection.on('reconnected', () => { | ||
logger.debug('MongoDB Connection Reestablished') | ||
}) | ||
|
||
mongoose.connection.on('disconnected', () => { | ||
logger.debug('MongoDB Connection Disconnected') | ||
}) | ||
|
||
mongoose.connection.on('close', () => { | ||
logger.debug('MongoDB Connection Closed') | ||
}) | ||
|
||
mongoose.connection.on('error', (error) => { | ||
logger.error('MongoDB ERROR: ' + error) | ||
}) | ||
|
||
async function connectMongoDB(){ | ||
await mongoose.connect(mongoConfig.url + '/' + mongoConfig.database, { | ||
useNewUrlParser: true, | ||
autoReconnect: true, | ||
reconnectTries: 1000000, | ||
reconnectInterval: 3000 | ||
}) | ||
} | ||
|
||
module.exports = { | ||
sqlServer : sqlServerPool, | ||
connectMongoDB: connectMongoDB | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const db = require('./db'); | ||
const poll = require('./poll'); | ||
|
||
const sqlServerPool = db.sqlServerPool; | ||
|
||
async function sync() { | ||
// await sqlServerPool.connect(); | ||
await db.connectMongoDB(); | ||
await poll.postFichada( | ||
{ | ||
"agente" : { | ||
"_id" : "5e53f48ed40607323c624b8f" | ||
}, | ||
"fecha" : "2013-09-27T14:06:46.000Z", | ||
"esEntrada" : false, | ||
"reloj" : 1, | ||
"format" : "RSI_DLF_IDENTITY_VERIFIED", | ||
"data1" : "0000001018", | ||
"data2" : "3" | ||
} | ||
) | ||
|
||
// let response = await fetch("/subscribe"); | ||
// if (response.status == 502) { | ||
// // Status 502 is a connection timeout error, | ||
// // may happen when the connection was pending for too long, | ||
// // and the remote server or a proxy closed it | ||
// // let's reconnect | ||
// await subscribe(); | ||
// } else if (response.status != 200) { | ||
// // An error - let's show it | ||
// showMessage(response.statusText); | ||
// // Reconnect in one second | ||
// await new Promise(resolve => setTimeout(resolve, 1000)); | ||
// await subscribe(); | ||
// } else { | ||
// // Get and show the message | ||
// let message = await response.text(); | ||
// showMessage(message); | ||
// // Call subscribe() again to get the next message | ||
// await subscribe(); | ||
// } | ||
} | ||
|
||
sync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const { createLogger, format, transports } = require('winston'); | ||
const Transport = require('winston-transport'); | ||
const { combine, timestamp, printf } = format; | ||
|
||
|
||
// Custom Output Format | ||
const printFormat = printf(({ level, message, timestamp}) => { | ||
return `${timestamp} [${level}]: ${message}`; | ||
}); | ||
|
||
const customFormat = combine( | ||
timestamp(), | ||
printFormat | ||
); | ||
|
||
|
||
// Custom Transport. Logs only info level to console | ||
class CustomInfoTransport extends Transport { | ||
constructor(options) { | ||
super(options); | ||
this.name = 'customLogger'; | ||
this.level = options && options.level || 'info'; | ||
this.levelOnly = options && options.levelOnly; | ||
this.levels = options && options.levels || []; | ||
} | ||
|
||
log(info, callback) { | ||
try{ | ||
|
||
if (this.levelOnly && info.level == this.level ) { | ||
console.log(`${info.timestamp} [${info.level}]: ${info.message}`); | ||
} | ||
this.emit('logged'); | ||
callback(); | ||
} | ||
catch (err){ | ||
console.log(err); | ||
} | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Final Logger Configuration | ||
* - Write all logs ONLY with level `info` to console | ||
* - Write all logs with level `error` and below to `error.log` | ||
* - Write all logs with level `debug` and below to `combined.log` | ||
*/ | ||
const logger = createLogger({ | ||
format: customFormat, | ||
exitOnError: false, | ||
transports: [ | ||
new CustomInfoTransport({ | ||
levelOnly: true, | ||
}), | ||
new transports.File({ filename: 'error.log', level: 'error' }), | ||
new transports.File({ filename: 'combined.log', level: 'debug' }) | ||
] | ||
}); | ||
|
||
// | ||
// If we're not in production then log to the `console` with the format: | ||
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) ` | ||
// | ||
// if (process.env.NODE_ENV !== 'production') { | ||
// logger.add(new winston.transports.Console({ | ||
// format: winston.format.simple() | ||
// })); | ||
// } | ||
|
||
module.exports = { | ||
logger : logger, | ||
printFormat: printFormat | ||
} |
Oops, something went wrong.