NaN bug fix
This commit is contained in:
@@ -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