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