Add cancelation charges
This commit is contained in:
@@ -111,6 +111,45 @@ const getUnscheduledIncidents = (startDate, endDate, memberId) => {
|
||||
});
|
||||
};
|
||||
|
||||
const getBookingChangeIncidents = (startDate, endDate, memberId) => {
|
||||
const attributes = [
|
||||
'id',
|
||||
'reservationId',
|
||||
'memberId',
|
||||
'resourceId',
|
||||
'oldBookingStart',
|
||||
'oldBookingEnd',
|
||||
'newBookingStart',
|
||||
'newBookingEnd',
|
||||
'incidentType',
|
||||
'chargeFee',
|
||||
'createdAt'
|
||||
];
|
||||
|
||||
const filters = {};
|
||||
|
||||
if (startDate && endDate) {
|
||||
filters.createdAt = {
|
||||
[Op.and]: {
|
||||
[Op.gte]: startDate.toISOString(),
|
||||
[Op.lte]: endDate.toISOString(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (memberId){
|
||||
filters.memberId = memberId;
|
||||
}
|
||||
|
||||
return db.bookingChangeIncident.findAll({
|
||||
attributes,
|
||||
where: filters,
|
||||
sort: [
|
||||
['createdAt', 'ASC']
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
const formatTime = (timestamp) => {
|
||||
const momentObject = moment.tz(timestamp, UI_TIMEZONE);
|
||||
if (momentObject.isValid()){
|
||||
@@ -120,13 +159,13 @@ const formatTime = (timestamp) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
const getAllIncidents = (dateRange, memberId) => {
|
||||
return new Promise ((resolve, reject) => {
|
||||
let startDate, endDate;
|
||||
|
||||
if (dateRange.startDate && dateRange.endDate){
|
||||
startDate = moment.tz(dateRange.startDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE);
|
||||
endDate = moment.tz(dateRange.endDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE);
|
||||
startDate = moment.tz(dateRange.startDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE).startOf('day');
|
||||
endDate = moment.tz(dateRange.endDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE).endOf('day');
|
||||
|
||||
if (!startDate.isValid() || !endDate.isValid() || endDate.isBefore(startDate)){
|
||||
reject(integrationServiceErrors.INVALID_DATE_RANGE);
|
||||
@@ -134,7 +173,14 @@ const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
}
|
||||
}
|
||||
|
||||
const dataFetchJobs = [fetchAllMembers(), fetchOffices(), fetchResources(), getUnlockedIncidents(startDate, endDate, memberId), getUnscheduledIncidents(startDate, endDate, memberId)];
|
||||
const dataFetchJobs = [
|
||||
fetchAllMembers(),
|
||||
fetchOffices(),
|
||||
fetchResources(),
|
||||
getUnlockedIncidents(startDate, endDate, memberId),
|
||||
getUnscheduledIncidents(startDate, endDate, memberId),
|
||||
getBookingChangeIncidents(startDate, endDate, memberId)
|
||||
];
|
||||
|
||||
Promise.all(dataFetchJobs)
|
||||
.then((data) => {
|
||||
@@ -143,6 +189,7 @@ const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
const resources = data[2];
|
||||
const unlockedIncidents = data[3];
|
||||
const unscheduledIncidents = data[4];
|
||||
const bookingChangeIncidents = data[5];
|
||||
|
||||
const membersMap = {};
|
||||
const officesMap = {};
|
||||
@@ -200,6 +247,39 @@ const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
});
|
||||
});
|
||||
|
||||
bookingChangeIncidents.forEach((bookingChangeIncident) => {
|
||||
const {
|
||||
id,
|
||||
memberId,
|
||||
resourceId,
|
||||
oldBookingStart,
|
||||
oldBookingEnd,
|
||||
newBookingStart,
|
||||
newBookingEnd,
|
||||
incidentType,
|
||||
chargeFee,
|
||||
createdAt,
|
||||
} = bookingChangeIncident;
|
||||
const memberName = membersMap[memberId].name;
|
||||
const resource = resourcesMap[resourceId];
|
||||
const resourceName = resource.resourceName;
|
||||
const officeName = officesMap[resource.officeId].officeName;
|
||||
allIncidents.push({
|
||||
incidentId: id,
|
||||
memberId,
|
||||
memberName,
|
||||
resourceName,
|
||||
officeName,
|
||||
oldBookingStart: formatTime(oldBookingStart),
|
||||
oldBookingEnd: formatTime(oldBookingEnd),
|
||||
newBookingStart: formatTime(newBookingStart),
|
||||
newBookingEnd: formatTime(newBookingEnd),
|
||||
incidentType,
|
||||
totalChargeFee: chargeFee,
|
||||
incidentTimestamp: formatTime(createdAt),
|
||||
});
|
||||
});
|
||||
|
||||
resolve(allIncidents);
|
||||
})
|
||||
.catch((error) => reject(error));
|
||||
@@ -209,5 +289,5 @@ const getAllDoorLockIncidents = (dateRange, memberId) => {
|
||||
module.exports = {
|
||||
getUnlockedIncidents,
|
||||
getUnscheduledIncidents,
|
||||
getAllDoorLockIncidents,
|
||||
getAllIncidents,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user