daysbooked in timezone Europe/Berlin

This commit is contained in:
Thomas Ruoff
2020-11-09 22:51:19 +01:00
parent e9a8dfaf32
commit cd6ae123bb
4 changed files with 15 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
import * as mongoose from 'mongoose'
import { v4 as uuidv4 } from 'uuid'
import { dateFormatBackend, getDays } from '../helpers/date'
import { dateFormatBackend, getDays, nowInTz } from '../helpers/date'
import { Bill } from './bill'
import { Booker } from './booker'
import { BOOKING_STATUS } from './enums'
@@ -89,12 +89,13 @@ BookingSchema.pre('save', function (next) {
BookingSchema.static('findBookedDays', async function (): Promise<string[]> {
const model = this as BookingModel
const now = nowInTz()
const bookedDays = await model
.find(
{
status: { $in: [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED] },
// dateFormatBackend uses YYYY-MM-DD, which is startOfDay anyway
endDate: { $gt: dateFormatBackend(new Date()) },
endDate: { $gt: dateFormatBackend(now) },
},
'days'
)