Fix missing fee problem when ORD returns missing membership information
This commit is contained in:
@@ -57,12 +57,16 @@ const csvParserErrors = {
|
|||||||
const officeRnDAPIErrors = {
|
const officeRnDAPIErrors = {
|
||||||
FAILED_TO_FETCH_MEMBERS: 'Failed to fetch members',
|
FAILED_TO_FETCH_MEMBERS: 'Failed to fetch members',
|
||||||
FAILED_TO_FETCH_BOOKINGS: 'Failed to fetch booking reservations',
|
FAILED_TO_FETCH_BOOKINGS: 'Failed to fetch booking reservations',
|
||||||
FAILED_TO_FETCH_FEES: 'Failed to fetch existing fees',
|
FAILED_TO_FETCH_FEES: 'Failed to fetch existing fees from ORD',
|
||||||
FAILED_TO_FETCH_PLANS: 'Failed to fetch plans',
|
FAILED_TO_FETCH_PLANS: 'Failed to fetch plans from ORD',
|
||||||
FAILED_TO_DELETE_FEES: 'Failed to delete fees in ORD',
|
FAILED_TO_DELETE_FEES: 'Failed to delete fees in ORD',
|
||||||
FAILED_TO_ADD_FEES: 'Failed to add fees in ORD',
|
FAILED_TO_ADD_FEES: 'Failed to add fees in ORD',
|
||||||
MEMBERSHIPS_ARE_NOT_LOADED_CORRECTLY: 'Memberships are not loaded correctly',
|
MEMBERSHIPS_ARE_NOT_LOADED_CORRECTLY: 'Memberships are not loaded correctly',
|
||||||
OAUTH_FAILED: 'Failed to fetch new OAUTH token',
|
OAUTH_FAILED: 'Failed to fetch new OAUTH token',
|
||||||
|
FAILED_TO_FETCH_DATA: 'Failed to fetch data from ORD. Please try again in a few minutes',
|
||||||
|
FAILED_TO_FETCH_RESOURCES: 'Failed to fetch resources data from ORD',
|
||||||
|
FAILED_TO_FETCH_RATES: 'Failed to fetch rates data from ORD',
|
||||||
|
FAILED_TO_UPDATE_MEMBERSHIP: 'Failed to update membership in ORD'
|
||||||
};
|
};
|
||||||
const integrationServiceErrors = {
|
const integrationServiceErrors = {
|
||||||
PROCESSING_TRY_AGAIN: 'Incident calculations are in progress. Please try again in a few minutes',
|
PROCESSING_TRY_AGAIN: 'Incident calculations are in progress. Please try again in a few minutes',
|
||||||
|
|||||||
@@ -147,28 +147,22 @@ const addFees = (req, res) => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log('Error reformatting memberships name');
|
|
||||||
console.log(error);
|
|
||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log('Error adding fees');
|
|
||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
|
||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
|
||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log('Error with updating booking reservations');
|
|
||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
const { fetchAllBookings, bulkWriteReservationsWithChangesTracking } = require('../officeRnD/bookings');
|
const { fetchAllBookings, bulkWriteReservationsWithChangesTracking } = require('../officeRnD/bookings');
|
||||||
const { fetchResources } = require('../officeRnD/resources');
|
const { fetchResources } = require('../officeRnD/resources');
|
||||||
const { fetchRates } = require('../officeRnD/rates');
|
const { fetchRates } = require('../officeRnD/rates');
|
||||||
|
const { officeRnDAPIErrors } = require('../../constants/constants');
|
||||||
const {
|
const {
|
||||||
getIncidentsFromChanges,
|
getIncidentsFromChanges,
|
||||||
bulkWriteBookingChangeIncidents,
|
bulkWriteBookingChangeIncidents,
|
||||||
@@ -77,8 +77,8 @@ const checkBookingChanges = () => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log('Error fetching bookings, resources and rates from ORD ', error);
|
console.log('\t> [Check Booking Changes] Error fetching bookings, resources and rates from ORD ', error);
|
||||||
reject(error);
|
reject(officeRnDAPIErrors.FAILED_TO_FETCH_DATA);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,180 +9,188 @@ const { DEFAULT_DATE_FORMAT, UI_TIMEZONE, incidentTypeExplanations, incidentType
|
|||||||
const { getResourceMappings } = require('../officeRnD/resources');
|
const { getResourceMappings } = require('../officeRnD/resources');
|
||||||
const { fetchAllMembers } = require('../officeRnD/members');
|
const { fetchAllMembers } = require('../officeRnD/members');
|
||||||
const { fetchAllMembershipsForMemberIds } = require('../officeRnD/memberships');
|
const { fetchAllMembershipsForMemberIds } = require('../officeRnD/memberships');
|
||||||
const { discounts, DISCOUNT_PLANS } = require('../../constants/constants');
|
const { discounts, DISCOUNT_PLANS, officeRnDAPIErrors } = require('../../constants/constants');
|
||||||
|
|
||||||
const createFeeFromIncident = (incident) => {
|
const createFeeFromIncident = (incident) => {
|
||||||
const {
|
try {
|
||||||
memberId,
|
const {
|
||||||
officeId,
|
memberId,
|
||||||
officeName,
|
officeId,
|
||||||
resourceName,
|
officeName,
|
||||||
oldResourceName,
|
resourceName,
|
||||||
newResourceName,
|
oldResourceName,
|
||||||
bookingStartRaw,
|
newResourceName,
|
||||||
bookingEndRaw,
|
bookingStartRaw,
|
||||||
oldBookingStartRaw,
|
bookingEndRaw,
|
||||||
oldBookingEndRaw,
|
oldBookingStartRaw,
|
||||||
newBookingStartRaw,
|
oldBookingEndRaw,
|
||||||
newBookingEndRaw,
|
newBookingStartRaw,
|
||||||
unlockTimestampRaw,
|
newBookingEndRaw,
|
||||||
lockTimestampRaw,
|
unlockTimestampRaw,
|
||||||
incidentLevel,
|
lockTimestampRaw,
|
||||||
timeIntervalsToCharge,
|
incidentLevel,
|
||||||
incidentPrice,
|
timeIntervalsToCharge,
|
||||||
chargePrice,
|
incidentPrice,
|
||||||
totalChargeFee,
|
chargePrice,
|
||||||
incidentTimestampRaw
|
totalChargeFee,
|
||||||
} = incident;
|
incidentTimestampRaw
|
||||||
const incidentTypeNumber = incident.incidentType;
|
} = incident;
|
||||||
|
const incidentTypeNumber = incident.incidentType;
|
||||||
|
|
||||||
let incidentExplanation = incidentTypeExplanations[incidentTypeNumber];
|
let incidentExplanation = incidentTypeExplanations[incidentTypeNumber];
|
||||||
|
|
||||||
let date = '';
|
let date = '';
|
||||||
let price = 0;
|
let price = 0;
|
||||||
let quantity = 0;
|
let quantity = 0;
|
||||||
let bookingTimeExplanation = '';
|
let bookingTimeExplanation = '';
|
||||||
let incidentTimeExplanation = '';
|
let incidentTimeExplanation = '';
|
||||||
|
|
||||||
let roomExplanation = '';
|
let roomExplanation = '';
|
||||||
let dateExplanation = '';
|
let dateExplanation = '';
|
||||||
|
|
||||||
const bookingStartMoment = moment.tz(bookingStartRaw, UI_TIMEZONE);
|
const bookingStartMoment = moment.tz(bookingStartRaw, UI_TIMEZONE);
|
||||||
const bookingEndMoment = moment.tz(bookingEndRaw, UI_TIMEZONE);
|
const bookingEndMoment = moment.tz(bookingEndRaw, UI_TIMEZONE);
|
||||||
const unlockMoment = moment.tz(unlockTimestampRaw, UI_TIMEZONE);
|
const unlockMoment = moment.tz(unlockTimestampRaw, UI_TIMEZONE);
|
||||||
const lockMoment = moment.tz(lockTimestampRaw, UI_TIMEZONE);
|
const lockMoment = moment.tz(lockTimestampRaw, UI_TIMEZONE);
|
||||||
|
|
||||||
const oldBookingStartMoment = moment.tz(oldBookingStartRaw, UI_TIMEZONE);
|
const oldBookingStartMoment = moment.tz(oldBookingStartRaw, UI_TIMEZONE);
|
||||||
const oldBookingEndMoment = moment.tz(oldBookingEndRaw, UI_TIMEZONE);
|
const oldBookingEndMoment = moment.tz(oldBookingEndRaw, UI_TIMEZONE);
|
||||||
const newBookingStartMoment = moment.tz(newBookingStartRaw, UI_TIMEZONE);
|
const newBookingStartMoment = moment.tz(newBookingStartRaw, UI_TIMEZONE);
|
||||||
const newBookingEndMoment = moment.tz(newBookingEndRaw, UI_TIMEZONE);
|
const newBookingEndMoment = moment.tz(newBookingEndRaw, UI_TIMEZONE);
|
||||||
|
|
||||||
const incidentTimestampMoment = moment.tz(incidentTimestampRaw, UI_TIMEZONE);
|
const incidentTimestampMoment = moment.tz(incidentTimestampRaw, UI_TIMEZONE);
|
||||||
|
|
||||||
switch (incidentTypeNumber){
|
switch (incidentTypeNumber) {
|
||||||
case incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
case incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
||||||
roomExplanation = resourceName;
|
roomExplanation = resourceName;
|
||||||
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
||||||
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
||||||
incidentExplanation += `, ${unlockedIncidentLevelsPrices[incidentLevel].description}, ${incidentTimeExplanation}`;
|
incidentExplanation += `, ${unlockedIncidentLevelsPrices[incidentLevel].description}, ${incidentTimeExplanation}`;
|
||||||
|
|
||||||
date = bookingStartMoment.clone().startOf('day').format();
|
date = bookingStartMoment.clone().startOf('day').format();
|
||||||
|
|
||||||
price = +incidentPrice.toFixed(2);
|
price = +incidentPrice.toFixed(2);
|
||||||
quantity = 1.00;
|
quantity = 1.00;
|
||||||
break;
|
break;
|
||||||
case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
||||||
roomExplanation = resourceName;
|
roomExplanation = resourceName;
|
||||||
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
||||||
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
||||||
incidentExplanation += `, ${incidentTimeExplanation}`;
|
incidentExplanation += `, ${incidentTimeExplanation}`;
|
||||||
|
|
||||||
date = bookingStartMoment.clone().startOf('day').format();
|
date = bookingStartMoment.clone().startOf('day').format();
|
||||||
|
|
||||||
price = +chargePrice.toFixed(2);
|
price = +chargePrice.toFixed(2);
|
||||||
quantity = +timeIntervalsToCharge.toFixed(2);
|
quantity = +timeIntervalsToCharge.toFixed(2);
|
||||||
break;
|
break;
|
||||||
case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
||||||
roomExplanation = resourceName;
|
roomExplanation = resourceName;
|
||||||
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
||||||
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `lock : ${lockMoment.clone().format('HH:mm')}`;
|
incidentTimeExplanation = `lock : ${lockMoment.clone().format('HH:mm')}`;
|
||||||
incidentExplanation += `, ${incidentTimeExplanation}`;
|
incidentExplanation += `, ${incidentTimeExplanation}`;
|
||||||
|
|
||||||
date = bookingStartMoment.clone().startOf('day').format();
|
date = bookingStartMoment.clone().startOf('day').format();
|
||||||
|
|
||||||
price = +chargePrice.toFixed(2);
|
price = +chargePrice.toFixed(2);
|
||||||
quantity = +timeIntervalsToCharge.toFixed(2);
|
quantity = +timeIntervalsToCharge.toFixed(2);
|
||||||
break;
|
break;
|
||||||
case incidentType.UNLOCKED_INCIDENT_STANDALONE:
|
case incidentType.UNLOCKED_INCIDENT_STANDALONE:
|
||||||
roomExplanation = resourceName;
|
roomExplanation = resourceName;
|
||||||
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
|
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
|
||||||
bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
||||||
incidentExplanation += `, ${unlockedIncidentLevelsPrices[incidentLevel].description}, ${incidentTimeExplanation}`;
|
incidentExplanation += `, ${unlockedIncidentLevelsPrices[incidentLevel].description}, ${incidentTimeExplanation}`;
|
||||||
|
|
||||||
date = unlockMoment.clone().startOf('day').format();
|
date = unlockMoment.clone().startOf('day').format();
|
||||||
|
|
||||||
price = +incidentPrice.toFixed(2);
|
price = +incidentPrice.toFixed(2);
|
||||||
quantity = 1.00;
|
quantity = 1.00;
|
||||||
break;
|
break;
|
||||||
case incidentType.UNSCHEDULED_INCIDENT_STANDALONE:
|
case incidentType.UNSCHEDULED_INCIDENT_STANDALONE:
|
||||||
roomExplanation = resourceName;
|
roomExplanation = resourceName;
|
||||||
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
|
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
|
||||||
bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`;
|
||||||
//incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}, lock : ${lockMoment.clone().format('HH:mm')}`;
|
//incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}, lock : ${lockMoment.clone().format('HH:mm')}`;
|
||||||
|
|
||||||
date = unlockMoment.clone().startOf('day').format();
|
date = unlockMoment.clone().startOf('day').format();
|
||||||
|
|
||||||
price = +chargePrice.toFixed(2);
|
price = +chargePrice.toFixed(2);
|
||||||
quantity = +timeIntervalsToCharge.toFixed(2);
|
quantity = +timeIntervalsToCharge.toFixed(2);
|
||||||
break;
|
break;
|
||||||
case incidentType.BOOKING_MOVED_TO_ANOTHER_DAY:
|
case incidentType.BOOKING_MOVED_TO_ANOTHER_DAY:
|
||||||
// if (oldResourceName !== newResourceName){
|
// if (oldResourceName !== newResourceName){
|
||||||
// roomExplanation = `${oldResourceName} -> ${newResourceName}`;
|
// roomExplanation = `${oldResourceName} -> ${newResourceName}`;
|
||||||
// }else{
|
// }else{
|
||||||
// roomExplanation = oldResourceName;
|
// roomExplanation = oldResourceName;
|
||||||
// }
|
// }
|
||||||
roomExplanation = newResourceName;
|
roomExplanation = newResourceName;
|
||||||
|
|
||||||
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')} -> ${newBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')} -> ${newBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
||||||
dateExplanation = `${newBookingStartMoment.clone().format('MMM DD')}`;
|
dateExplanation = `${newBookingStartMoment.clone().format('MMM DD')}`;
|
||||||
bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `moved on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
|
incidentTimeExplanation = `moved on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
|
||||||
incidentExplanation += `, ${incidentTimeExplanation}`;
|
incidentExplanation += `, ${incidentTimeExplanation}`;
|
||||||
|
|
||||||
date = incidentTimestampMoment.clone().startOf('day').format();
|
date = incidentTimestampMoment.clone().startOf('day').format();
|
||||||
|
|
||||||
price = +totalChargeFee.toFixed(2);
|
price = +totalChargeFee.toFixed(2);
|
||||||
quantity = 1.00;
|
quantity = 1.00;
|
||||||
break;
|
break;
|
||||||
case incidentType.BOOKING_SHORTENED:
|
case incidentType.BOOKING_SHORTENED:
|
||||||
// if (oldResourceName !== newResourceName){
|
// if (oldResourceName !== newResourceName){
|
||||||
// roomExplanation = `${oldResourceName} -> ${newResourceName}`;
|
// roomExplanation = `${oldResourceName} -> ${newResourceName}`;
|
||||||
// }else{
|
// }else{
|
||||||
// roomExplanation = oldResourceName;
|
// roomExplanation = oldResourceName;
|
||||||
// }
|
// }
|
||||||
roomExplanation = newResourceName;
|
roomExplanation = newResourceName;
|
||||||
|
|
||||||
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
||||||
dateExplanation = `${newBookingStartMoment.clone().format('MMM DD')}`;
|
dateExplanation = `${newBookingStartMoment.clone().format('MMM DD')}`;
|
||||||
bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `shortened on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
|
incidentTimeExplanation = `shortened on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
|
||||||
incidentExplanation += `, ${incidentTimeExplanation}`;
|
incidentExplanation += `, ${incidentTimeExplanation}`;
|
||||||
|
|
||||||
date = incidentTimestampMoment.clone().startOf('day').format();
|
date = incidentTimestampMoment.clone().startOf('day').format();
|
||||||
|
|
||||||
price = +totalChargeFee.toFixed(2);
|
price = +totalChargeFee.toFixed(2);
|
||||||
quantity = 1.00;
|
quantity = 1.00;
|
||||||
break;
|
break;
|
||||||
case incidentType.BOOKING_CANCELED_LATE:
|
case incidentType.BOOKING_CANCELED_LATE:
|
||||||
roomExplanation = oldResourceName;
|
roomExplanation = oldResourceName;
|
||||||
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
||||||
dateExplanation = `${oldBookingStartMoment.clone().format('MMM DD')}`;
|
dateExplanation = `${oldBookingStartMoment.clone().format('MMM DD')}`;
|
||||||
bookingTimeExplanation = `[${oldBookingStartMoment.clone().format('HH:mm')} to ${oldBookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${oldBookingStartMoment.clone().format('HH:mm')} to ${oldBookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `canceled on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
|
incidentTimeExplanation = `canceled on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
|
||||||
incidentExplanation += `, ${incidentTimeExplanation}`;
|
incidentExplanation += `, ${incidentTimeExplanation}`;
|
||||||
|
|
||||||
date = incidentTimestampMoment.clone().startOf('day').format();
|
date = incidentTimestampMoment.clone().startOf('day').format();
|
||||||
|
|
||||||
price = +totalChargeFee.toFixed(2);
|
price = +totalChargeFee.toFixed(2);
|
||||||
quantity = 1.00;
|
quantity = 1.00;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const formattedName = `${dateExplanation} ${bookingTimeExplanation} ${roomExplanation}, ${officeName}, ${incidentExplanation}`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: formattedName,
|
||||||
|
price,
|
||||||
|
quantity,
|
||||||
|
date,
|
||||||
|
member: memberId,
|
||||||
|
team: null,
|
||||||
|
office: officeId,
|
||||||
|
isPersonal: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (e) {
|
||||||
const formattedName = `${dateExplanation} ${bookingTimeExplanation} ${roomExplanation}, ${officeName}, ${incidentExplanation}`;
|
console.log("[Create Fee From Incident] Incident is incomplete, it will not be added");
|
||||||
|
console.log(e);
|
||||||
return {
|
console.log(">> INCIDENT : ", incident);
|
||||||
name: formattedName,
|
return null;
|
||||||
price,
|
|
||||||
quantity,
|
|
||||||
date,
|
|
||||||
member: memberId,
|
|
||||||
team: null,
|
|
||||||
office: officeId,
|
|
||||||
isPersonal: false,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -320,7 +328,10 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => {
|
|||||||
const allFees = [];
|
const allFees = [];
|
||||||
|
|
||||||
allIncidents.forEach((incident) => {
|
allIncidents.forEach((incident) => {
|
||||||
allFees.push(createFeeFromIncident(incident));
|
const feeFromIncident = createFeeFromIncident(incident);
|
||||||
|
if (feeFromIncident){
|
||||||
|
allFees.push(createFeeFromIncident(incident));
|
||||||
|
}
|
||||||
|
|
||||||
const incidentsValuableForDiscountCalculation = [
|
const incidentsValuableForDiscountCalculation = [
|
||||||
incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION,
|
incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION,
|
||||||
@@ -399,18 +410,22 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
membersMap[memberId].bookingData.totalChargedHours += chargedBookingLength;
|
if (membersMap[memberId] && membersMap[memberId].bookingData){
|
||||||
membersMap[memberId].bookingData.totalBookingChargedFee += totalChargeFee;
|
membersMap[memberId].bookingData.totalChargedHours += chargedBookingLength;
|
||||||
|
membersMap[memberId].bookingData.totalBookingChargedFee += totalChargeFee;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
allBookings.forEach((booking) => {
|
allBookings.forEach((booking) => {
|
||||||
const {memberId, start, end, timezone, hourlyRate, canceled } = booking.get();
|
const {memberId, start, end, timezone, hourlyRate, canceled } = booking.get();
|
||||||
const startMoment = moment.tz(start, timezone);
|
const startMoment = moment.tz(start, timezone);
|
||||||
const endMoment = moment.tz(end, timezone);
|
const endMoment = moment.tz(end, timezone);
|
||||||
|
|
||||||
if (startMoment.isValid() && endMoment.isValid()) {
|
const memberMappingExists = !!membersMap[memberId];
|
||||||
|
|
||||||
|
if (startMoment.isValid() && endMoment.isValid() && memberMappingExists) {
|
||||||
const bookingLength = endMoment.diff(startMoment, 'hours', true);
|
const bookingLength = endMoment.diff(startMoment, 'hours', true);
|
||||||
|
|
||||||
if (!membersMap[memberId] || !membersMap[memberId].bookingData) {
|
if (!membersMap[memberId].bookingData) {
|
||||||
membersMap[memberId].bookingData = Object.assign({}, oneMemberObject);
|
membersMap[memberId].bookingData = Object.assign({}, oneMemberObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,25 +438,34 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => {
|
|||||||
|
|
||||||
allFees.push(createFeeFromBooking(booking, resourceMappings));
|
allFees.push(createFeeFromBooking(booking, resourceMappings));
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
console.log('[Get Members Fees For Date Range] Start Moment / End Moment / Member Mapping is invalid for member : ', memberId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//add discount
|
//add discount
|
||||||
memberIdsToUse.forEach((memberId) => {
|
memberIdsToUse.forEach((memberId) => {
|
||||||
const discountFee = createNegativeFeeForDiscount(membersMap[memberId], dateRange);
|
if (membersMap[memberId]){
|
||||||
if (discountFee){
|
const discountFee = createNegativeFeeForDiscount(membersMap[memberId], dateRange);
|
||||||
allFees.push(discountFee);
|
if (discountFee){
|
||||||
|
allFees.push(discountFee);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
console.log('[Get Members Fees For Date Range] Member mapping unknown for member : ', memberId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
allFees.forEach((fee) => {
|
allFees.forEach((fee) => {
|
||||||
const { member } = fee;
|
const { member } = fee;
|
||||||
const { teamId, name: memberName} = membersMap[member].member;
|
const memberFromMapping = membersMap[member];
|
||||||
|
if (memberFromMapping && memberFromMapping.member){
|
||||||
|
const { teamId, name: memberName} = memberFromMapping.member;
|
||||||
|
|
||||||
fee.team = memberIdTeamMappings[member] || null;
|
fee.team = memberIdTeamMappings[member] || null;
|
||||||
if (teamId){
|
if (teamId){
|
||||||
//if member is part of the company, add name to the fee description/name
|
//if member is part of the company, add name to the fee description/name
|
||||||
fee.name += `, ${memberName}`;
|
fee.name += `, ${memberName}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -449,8 +473,8 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => {
|
|||||||
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
console.log("[Get Members Fees For Date Range] Error fetching data : ",error);
|
||||||
reject(error);
|
reject(officeRnDAPIErrors.FAILED_TO_FETCH_DATA);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -68,13 +68,13 @@ const deleteFeesFromORD = (dateRange, memberIds) => {
|
|||||||
resolve(feesToSkip);
|
resolve(feesToSkip);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log('error : ', error);
|
console.log('[Delete Fees From ORD] Error deleting fees from ORD : ', error);
|
||||||
reject(error);
|
reject(officeRnDAPIErrors.FAILED_TO_DELETE_FEES);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
console.log("[Delete Fees From ORD] Error fetching fees and plans from ORD : ", error);
|
||||||
reject(`${officeRnDAPIErrors.FAILED_TO_FETCH_FEES} or ${officeRnDAPIErrors.FAILED_TO_FETCH_PLANS}`);
|
reject(`${officeRnDAPIErrors.FAILED_TO_FETCH_FEES} and ${officeRnDAPIErrors.FAILED_TO_FETCH_PLANS}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -96,11 +96,13 @@ const addFeesToORD = (allFees, invoicedFees) => {
|
|||||||
const nonInvoicedFees = allFees.filter(isFeeNonInvoiced);
|
const nonInvoicedFees = allFees.filter(isFeeNonInvoiced);
|
||||||
|
|
||||||
API.post('/fees', nonInvoicedFees)
|
API.post('/fees', nonInvoicedFees)
|
||||||
|
.then(() => {
|
||||||
|
resolve(nonInvoicedFees.length);
|
||||||
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log('==== ERROR ====');
|
console.log('[Add Fees To ORD] Failed to send fees to ORD', error);
|
||||||
console.log(error);
|
reject(officeRnDAPIErrors.FAILED_TO_ADD_FEES);
|
||||||
});
|
});
|
||||||
resolve(nonInvoicedFees.length);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const fetchAllMembershipsForMemberIds = (memberIds) => {
|
|||||||
resolve(memberships);
|
resolve(memberships);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
console.log('[Fetch All Memberships For Member Ids] Error fetching memberships - expected member IDs array');
|
||||||
reject(integrationServiceErrors.EXPECTED_MEMBER_IDS_ARRAY);
|
reject(integrationServiceErrors.EXPECTED_MEMBER_IDS_ARRAY);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -48,7 +49,10 @@ const reformatMembershipsName = (memberships) => {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
})
|
})
|
||||||
.catch((error) => reject(error));
|
.catch((error) => {
|
||||||
|
console.log('[Reformat Memberships Name] Failed to update memberships : ', error);
|
||||||
|
reject(officeRnDAPIErrors.FAILED_TO_UPDATE_MEMBERSHIP);
|
||||||
|
});
|
||||||
}else{
|
}else{
|
||||||
reject(officeRnDAPIErrors.MEMBERSHIPS_ARE_NOT_LOADED_CORRECTLY);
|
reject(officeRnDAPIErrors.MEMBERSHIPS_ARE_NOT_LOADED_CORRECTLY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const { API } = require('../../helpers/api');
|
const { API } = require('../../helpers/api');
|
||||||
|
const { officeRnDAPIErrors } = require('../../constants/constants');
|
||||||
|
|
||||||
const fetchRates = () => {
|
const fetchRates = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -16,7 +17,8 @@ const fetchRates = () => {
|
|||||||
resolve(cleanedRates);
|
resolve(cleanedRates);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
reject(error);
|
console.log("[Fetch Rates] Failed to fetch rates : ", error);
|
||||||
|
reject(officeRnDAPIErrors.FAILED_TO_FETCH_RATES);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
const db = require('../../models/index');
|
const db = require('../../models/index');
|
||||||
|
|
||||||
const { API } = require('../../helpers/api');
|
const { API } = require('../../helpers/api');
|
||||||
|
const { officeRnDAPIErrors } = require('../../constants/constants');
|
||||||
|
|
||||||
const fetchOffices = () => {
|
const fetchOffices = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -41,7 +42,8 @@ const fetchResources = () => {
|
|||||||
resolve(cleanedResources);
|
resolve(cleanedResources);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
reject(error);
|
console.log("[Fetch resources] Failed to fetch resources : ", error);
|
||||||
|
reject(officeRnDAPIErrors.FAILED_TO_FETCH_RESOURCES);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user