stopping reservation of dangerous (<5hr until start) reservations
This commit is contained in:
parent
736e1f4d39
commit
bedd062aa0
1 changed files with 16 additions and 2 deletions
|
|
@ -12,6 +12,7 @@ import {
|
||||||
RESERVATIONS_QUEUE_NAME,
|
RESERVATIONS_QUEUE_NAME,
|
||||||
ReservationsQueue,
|
ReservationsQueue,
|
||||||
} from '../reservations/config'
|
} from '../reservations/config'
|
||||||
|
import { Reservation } from '../reservations/entity'
|
||||||
import { ReservationsService } from '../reservations/service'
|
import { ReservationsService } from '../reservations/service'
|
||||||
import { WaitingListDetails } from './types'
|
import { WaitingListDetails } from './types'
|
||||||
|
|
||||||
|
|
@ -90,12 +91,25 @@ export class WaitingListService {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// don't book something within the ~~danger zone~~
|
||||||
|
const now = dayjs()
|
||||||
|
const { safe, dangerous } = reservations.reduce<{
|
||||||
|
safe: Reservation[]
|
||||||
|
dangerous: Reservation[]
|
||||||
|
}>(
|
||||||
|
(acc, res) =>
|
||||||
|
now.diff(res.dateRangeStart, 'hours') > 5
|
||||||
|
? { safe: [...acc.safe, res], dangerous: acc.dangerous }
|
||||||
|
: { safe: acc.safe, dangerous: [...acc.dangerous, res] },
|
||||||
|
{ safe: [], dangerous: [] },
|
||||||
|
)
|
||||||
|
|
||||||
this.loggerService.debug(
|
this.loggerService.debug(
|
||||||
`Found ${reservations.length} reservations on waiting list`,
|
`Found ${safe.length} safe reservations on waiting list (${dangerous.length} dangerous)`,
|
||||||
)
|
)
|
||||||
|
|
||||||
await this.reservationsQueue.addBulk(
|
await this.reservationsQueue.addBulk(
|
||||||
reservations.map((r) => ({
|
safe.map((r) => ({
|
||||||
data: { reservation: r, speedyMode: false },
|
data: { reservation: r, speedyMode: false },
|
||||||
opts: { attempts: 1 },
|
opts: { attempts: 1 },
|
||||||
})),
|
})),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue