logging, error boundry
This commit is contained in:
@ -390,43 +390,7 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
|
||||
///console.log(`publishers: ${publishers.length}, WhereClause: ${JSON.stringify(whereClause)}`);
|
||||
|
||||
// include repeating weekly availabilities. generate occurrences for the month
|
||||
// convert matching weekly availabilities to availabilities for the day to make further processing easier on the client.
|
||||
publishers.forEach(pub => {
|
||||
pub.availabilities = pub.availabilities.map(avail => {
|
||||
if (avail.dayOfMonth == null) {
|
||||
if (filterAvailabilitiesByDate && !isForTheMonth) {
|
||||
// filter out repeating availabilities when on other day of week
|
||||
if (filterTimeFrom) {
|
||||
if (avail.dayofweek != dayOfWeekEnum) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
let newStart = new Date(filterDate);
|
||||
newStart.setHours(avail.startTime.getHours(), avail.startTime.getMinutes(), 0, 0);
|
||||
let newEnd = new Date(filterDate);
|
||||
newEnd.setHours(avail.endTime.getHours(), avail.endTime.getMinutes(), 0, 0);
|
||||
return {
|
||||
...avail,
|
||||
startTime: newStart,
|
||||
endTime: newEnd
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (filterAvailabilitiesByDate && !isForTheMonth) {
|
||||
if (avail.startTime >= filterTimeFrom && avail.startTime <= filterTimeTo) {
|
||||
return avail;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return avail;
|
||||
}
|
||||
})
|
||||
.filter(avail => avail !== null);
|
||||
});
|
||||
|
||||
|
||||
// ---------------------------------------------- statistics ----------------------------------------------
|
||||
let currentWeekStart, currentWeekEnd;
|
||||
|
||||
if (isWithStats) {
|
||||
@ -494,8 +458,45 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
||||
return avail.startTime >= filterDate && avail.startTime <= filterTimeTo;
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// ----------------------------------------------
|
||||
// include repeating weekly availabilities. generate occurrences for the month
|
||||
// convert matching weekly availabilities to availabilities for the day to make further processing easier on the client.
|
||||
publishers.forEach(pub => {
|
||||
pub.availabilities = pub.availabilities.map(avail => {
|
||||
if (avail.dayOfMonth == null) {
|
||||
if (filterAvailabilitiesByDate && !isForTheMonth) {
|
||||
// filter out repeating availabilities when on other day of week
|
||||
if (filterTimeFrom) {
|
||||
if (avail.dayofweek != dayOfWeekEnum) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
let newStart = new Date(filterDate);
|
||||
newStart.setHours(avail.startTime.getHours(), avail.startTime.getMinutes(), 0, 0);
|
||||
let newEnd = new Date(filterDate);
|
||||
newEnd.setHours(avail.endTime.getHours(), avail.endTime.getMinutes(), 0, 0);
|
||||
return {
|
||||
...avail,
|
||||
startTime: newStart,
|
||||
endTime: newEnd
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (filterAvailabilitiesByDate && !isForTheMonth) {
|
||||
if (avail.startTime >= filterTimeFrom && avail.startTime <= filterTimeTo) {
|
||||
return avail;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return avail;
|
||||
}
|
||||
})
|
||||
.filter(avail => avail !== null);
|
||||
});
|
||||
|
||||
// ToDo: test case/unit test
|
||||
// ToDo: check and validate the filtering and calculations
|
||||
if (isExactTime) {
|
||||
|
@ -1,11 +1,22 @@
|
||||
const winston = require('winston');
|
||||
require('winston-daily-rotate-file');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Define the logs directory path
|
||||
const logDirectory = path.join(__dirname, '../logs');
|
||||
|
||||
// Ensure the logs directory exists
|
||||
if (!fs.existsSync(logDirectory)) {
|
||||
fs.mkdirSync(logDirectory);
|
||||
}
|
||||
|
||||
// Define the log configuration
|
||||
const logConfiguration = {
|
||||
'transports': [
|
||||
transports: [
|
||||
new winston.transports.DailyRotateFile({
|
||||
filename: './logs/application-%DATE%.log',
|
||||
datePattern: 'YYYY-MM-DD', // new file is created every hour: 'YYYY-MM-DD-HH'
|
||||
filename: path.join(logDirectory, 'application-%DATE%.log'),
|
||||
datePattern: 'YYYY-MM-DD', // new file is created every day
|
||||
zippedArchive: true,
|
||||
maxSize: '20m',
|
||||
maxFiles: '90d',
|
||||
@ -20,6 +31,7 @@ const logConfiguration = {
|
||||
)
|
||||
};
|
||||
|
||||
// Create the logger
|
||||
const logger = winston.createLogger(logConfiguration);
|
||||
|
||||
module.exports = logger;
|
||||
|
Reference in New Issue
Block a user