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,
|
||||
ReservationsQueue,
|
||||
} from '../reservations/config'
|
||||
import { Reservation } from '../reservations/entity'
|
||||
import { ReservationsService } from '../reservations/service'
|
||||
import { WaitingListDetails } from './types'
|
||||
|
||||
|
|
@ -90,12 +91,25 @@ export class WaitingListService {
|
|||
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(
|
||||
`Found ${reservations.length} reservations on waiting list`,
|
||||
`Found ${safe.length} safe reservations on waiting list (${dangerous.length} dangerous)`,
|
||||
)
|
||||
|
||||
await this.reservationsQueue.addBulk(
|
||||
reservations.map((r) => ({
|
||||
safe.map((r) => ({
|
||||
data: { reservation: r, speedyMode: false },
|
||||
opts: { attempts: 1 },
|
||||
})),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue