NaN bug fix
This commit is contained in:
@@ -118,7 +118,7 @@ const SingleIncidentsTable = props => {
|
||||
}
|
||||
break;
|
||||
case 'totalChargeFee':
|
||||
const totalFee = props.value ? props.value : props.row['_original'].incidentPrice;
|
||||
const totalFee = (props.row['_original'].incidentPrice || props.value) || 0;
|
||||
const totalFeeFormatted = parseFloat(totalFee).toFixed(2);
|
||||
cellValue = `$ ${totalFeeFormatted}`;
|
||||
columnContentsAlignment = columnAlignments.right;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const { fetchAllBookings, bulkWriteReservationsWithChangesTracking } = require('../officeRnD/bookings');
|
||||
const { fetchResources } = require('../officeRnD/resources');
|
||||
const { fetchRates } = require('../officeRnD/rates');
|
||||
|
||||
const {
|
||||
getIncidentsFromChanges,
|
||||
@@ -12,9 +14,27 @@ const { bulkWriteChanges } = require('./bookingChangeLog');
|
||||
|
||||
const checkBookingChanges = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetchAllBookings()
|
||||
.then((reservations) => {
|
||||
bulkWriteReservationsWithChangesTracking(reservations)
|
||||
const asyncFetchActions = [fetchAllBookings(), fetchResources(), fetchRates()];
|
||||
Promise.all(asyncFetchActions)
|
||||
.then((asyncData) => {
|
||||
const reservations = asyncData[0];
|
||||
const resources = asyncData[1];
|
||||
const rates = asyncData[2];
|
||||
|
||||
const ratesMap = {};
|
||||
rates.forEach(rate => {
|
||||
const { rateId, price } = rate;
|
||||
ratesMap[rateId] = price;
|
||||
});
|
||||
|
||||
const resourcesMap = {};
|
||||
resources.forEach(resource => {
|
||||
const { resourceId, rate } = resource;
|
||||
resource.price = ratesMap[rate] || 0;
|
||||
resourcesMap[resourceId] = resource;
|
||||
});
|
||||
|
||||
bulkWriteReservationsWithChangesTracking(reservations, resourcesMap)
|
||||
.then((changes) => {
|
||||
bulkWriteChanges(changes)
|
||||
.then(() => {
|
||||
@@ -57,7 +77,7 @@ const checkBookingChanges = () => {
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('Error fetching bookings from ORD ', error);
|
||||
console.log('Error fetching bookings, resources and rates from ORD ', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -165,7 +165,7 @@ const writeBookingReservation = (bookingReservation) => {
|
||||
return db.bookingReservation.findOrCreate({where: {...bookingReservationForDB}, defaults: {...bookingReservationForDB}});
|
||||
};
|
||||
|
||||
const bulkWriteReservationsWithChangesTracking = (reservations) => {
|
||||
const bulkWriteReservationsWithChangesTracking = (reservations, resourcesMap) => {
|
||||
return new Promise ((resolve, reject) => {
|
||||
const changes = [];
|
||||
const asyncJobs = [];
|
||||
@@ -184,8 +184,18 @@ const bulkWriteReservationsWithChangesTracking = (reservations) => {
|
||||
}
|
||||
});
|
||||
|
||||
if (instance.hourlyRate === 0 && parseFloat(instance.previous('hourlyRate')) > 0){
|
||||
instance.setDataValue('hourlyRate', instance.previous('hourlyRate'));
|
||||
const previousResourceId = instance.previous('resourceId');
|
||||
const currentResourceId = instance.resourceId;
|
||||
|
||||
const resourceId = currentResourceId ? currentResourceId : previousResourceId;
|
||||
|
||||
if (instance.hourlyRate === 0 || isNaN(instance.hourlyRate)){
|
||||
if (parseFloat(instance.previous('hourlyRate') > 0)) {
|
||||
instance.setDataValue('hourlyRate', instance.previous('hourlyRate'));
|
||||
}else{
|
||||
const hourlyRate = resourceId ? resourcesMap[resourceId].price : 0;
|
||||
instance.setDataValue('hourlyRate', hourlyRate);
|
||||
}
|
||||
}
|
||||
|
||||
if (realChange){
|
||||
|
||||
26
services/officeRnD/rates.js
Normal file
26
services/officeRnD/rates.js
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
const { API } = require('../../helpers/api');
|
||||
|
||||
const fetchRates = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
API.get('/rates')
|
||||
.then((result) => {
|
||||
const rates = result.data || [];
|
||||
const cleanedRates = [];
|
||||
rates.forEach(rate => {
|
||||
cleanedRates.push({
|
||||
rateId: rate['_id'],
|
||||
price: rate.price,
|
||||
});
|
||||
});
|
||||
resolve(cleanedRates);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
fetchRates
|
||||
};
|
||||
@@ -35,6 +35,7 @@ const fetchResources = () => {
|
||||
resourceId: resource['_id'],
|
||||
resourceName: resource.name,
|
||||
officeId: resource.office,
|
||||
rate: resource.rate,
|
||||
});
|
||||
});
|
||||
resolve(cleanedResources);
|
||||
|
||||
Reference in New Issue
Block a user