From 4de9e1d9a0961c349feaa21bd938af5680141f35 Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Fri, 4 Oct 2019 17:31:35 +0200 Subject: [PATCH] Fix missing fee problem when ORD returns missing membership information --- constants/constants.js | 8 +- controllers/integration.js | 6 - services/integration/checkBookingChange.js | 6 +- services/integration/invoiceIntegration.js | 346 +++++++++++---------- services/officeRnD/fees.js | 16 +- services/officeRnD/memberships.js | 6 +- services/officeRnD/rates.js | 4 +- services/officeRnD/resources.js | 4 +- 8 files changed, 214 insertions(+), 182 deletions(-) diff --git a/constants/constants.js b/constants/constants.js index dff9ef5..e603879 100644 --- a/constants/constants.js +++ b/constants/constants.js @@ -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', diff --git a/controllers/integration.js b/controllers/integration.js index 0beca39..be3ffed 100644 --- a/controllers/integration.js +++ b/controllers/integration.js @@ -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{ diff --git a/services/integration/checkBookingChange.js b/services/integration/checkBookingChange.js index bd7fa95..e34c350 100644 --- a/services/integration/checkBookingChange.js +++ b/services/integration/checkBookingChange.js @@ -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); }); }); }; diff --git a/services/integration/invoiceIntegration.js b/services/integration/invoiceIntegration.js index 26d78b3..e1f5a64 100644 --- a/services/integration/invoiceIntegration.js +++ b/services/integration/invoiceIntegration.js @@ -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); }); }); }; diff --git a/services/officeRnD/fees.js b/services/officeRnD/fees.js index 6d421fe..8833839 100644 --- a/services/officeRnD/fees.js +++ b/services/officeRnD/fees.js @@ -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); }); }; diff --git a/services/officeRnD/memberships.js b/services/officeRnD/memberships.js index fbef195..445a8ed 100644 --- a/services/officeRnD/memberships.js +++ b/services/officeRnD/memberships.js @@ -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); } diff --git a/services/officeRnD/rates.js b/services/officeRnD/rates.js index e78b953..898c3fe 100644 --- a/services/officeRnD/rates.js +++ b/services/officeRnD/rates.js @@ -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); }); }); }; diff --git a/services/officeRnD/resources.js b/services/officeRnD/resources.js index 6f6ed47..4d8024c 100644 --- a/services/officeRnD/resources.js +++ b/services/officeRnD/resources.js @@ -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); }); }); };