Spaces:
Sleeping
Sleeping
Commit ·
91a40bb
1
Parent(s): 8db867e
Soft restore backend - clean controllers, restore history APIs
Browse files
src/controllers/dealController.js
CHANGED
|
@@ -4,8 +4,6 @@ const { pushToUser } = require('../utils/notificationHelper');
|
|
| 4 |
const { RIDE_STATUS, DEAL_STATUS, ACTIVE_DEAL_STATUSES } = require('../constants/statuses');
|
| 5 |
|
| 6 |
const PLATFORM_FEE_PERCENT = 0.1;
|
| 7 |
-
const ACTIVE_RIDE_STATUSES = new Set(['active', 'in_progress']);
|
| 8 |
-
const ACTIVE_BOOKING_STATUSES = new Set(['pending', 'confirmed', 'started']);
|
| 9 |
|
| 10 |
function generalPickupArea(address) {
|
| 11 |
if (!address || typeof address !== 'string') return 'Along route';
|
|
@@ -23,12 +21,6 @@ function maskCaptainPhone(phone) {
|
|
| 23 |
return '03**-*****';
|
| 24 |
}
|
| 25 |
|
| 26 |
-
function isUpcomingOrActiveDeparture(departureTime) {
|
| 27 |
-
const dt = Date.parse(departureTime || '');
|
| 28 |
-
if (!Number.isFinite(dt)) return true;
|
| 29 |
-
return dt >= Date.now() - 5 * 60 * 1000;
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
/** Apply seat delta inside a transaction; returns new available seat count. */
|
| 33 |
function seatUpdateFromRide(ride, delta) {
|
| 34 |
const totalSeats = ride.totalSeats ?? ride.availableSeats ?? 0;
|
|
@@ -583,22 +575,10 @@ const getMyBookings = async (req, res) => {
|
|
| 583 |
const bookings = [];
|
| 584 |
for (const doc of snap.docs) {
|
| 585 |
let deal = { id: doc.id, ...doc.data() };
|
| 586 |
-
if (
|
| 587 |
-
!ACTIVE_BOOKING_STATUSES.has((deal.status || '').toString().toLowerCase()) ||
|
| 588 |
-
!isUpcomingOrActiveDeparture(deal.ride?.departureTime || deal.departureTime)
|
| 589 |
-
) {
|
| 590 |
-
continue;
|
| 591 |
-
}
|
| 592 |
const phoneRevealed = deal.phoneRevealed === true;
|
| 593 |
const fullCaptainPhone = deal.captainPhone || '';
|
| 594 |
deal.captainPhone = phoneRevealed ? fullCaptainPhone : maskCaptainPhone(fullCaptainPhone);
|
| 595 |
deal = await populateRide(deal);
|
| 596 |
-
if (
|
| 597 |
-
!ACTIVE_RIDE_STATUSES.has((deal.ride?.status || '').toString().toLowerCase()) &&
|
| 598 |
-
!isUpcomingOrActiveDeparture(deal.ride?.departureTime)
|
| 599 |
-
) {
|
| 600 |
-
continue;
|
| 601 |
-
}
|
| 602 |
bookings.push(deal);
|
| 603 |
}
|
| 604 |
return res.json({ success: true, bookings });
|
|
|
|
| 4 |
const { RIDE_STATUS, DEAL_STATUS, ACTIVE_DEAL_STATUSES } = require('../constants/statuses');
|
| 5 |
|
| 6 |
const PLATFORM_FEE_PERCENT = 0.1;
|
|
|
|
|
|
|
| 7 |
|
| 8 |
function generalPickupArea(address) {
|
| 9 |
if (!address || typeof address !== 'string') return 'Along route';
|
|
|
|
| 21 |
return '03**-*****';
|
| 22 |
}
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
/** Apply seat delta inside a transaction; returns new available seat count. */
|
| 25 |
function seatUpdateFromRide(ride, delta) {
|
| 26 |
const totalSeats = ride.totalSeats ?? ride.availableSeats ?? 0;
|
|
|
|
| 575 |
const bookings = [];
|
| 576 |
for (const doc of snap.docs) {
|
| 577 |
let deal = { id: doc.id, ...doc.data() };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 578 |
const phoneRevealed = deal.phoneRevealed === true;
|
| 579 |
const fullCaptainPhone = deal.captainPhone || '';
|
| 580 |
deal.captainPhone = phoneRevealed ? fullCaptainPhone : maskCaptainPhone(fullCaptainPhone);
|
| 581 |
deal = await populateRide(deal);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 582 |
bookings.push(deal);
|
| 583 |
}
|
| 584 |
return res.json({ success: true, bookings });
|