Skip to content

Commit

Permalink
Adjust date handling in VehicleScheduler and add new booking button i…
Browse files Browse the repository at this point in the history
…n Scheduler
  • Loading branch information
aelassas committed Jan 24, 2025
1 parent 20b147f commit a1e11f4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
14 changes: 12 additions & 2 deletions api/src/controllers/bookingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,19 @@ export const getBookings = async (req: Request, res: Response) => {
}

if (dateBetween) {
$match.$and!.push({ $and: [{ from: { $lte: dateBetween } }, { to: { $gte: dateBetween } }] })
const dateBetweenStart = new Date(dateBetween)
dateBetweenStart.setHours(0, 0, 0, 0)
const dateBetweenEnd = new Date(dateBetween)
dateBetweenEnd.setHours(23, 59, 59, 999)

$match.$and!.push({
$and: [
{ from: { $lte: dateBetweenEnd } },
{ to: { $gte: dateBetweenStart } },
],
})
} else if (from) {
$match.$and!.push({ from: { $gte: from } }) // $from > from
$match.$and!.push({ from: { $gte: from } }) // $from >= from
}

if (to) {
Expand Down
10 changes: 10 additions & 0 deletions backend/src/assets/css/scheduler.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ div.scheduler {
padding-right: 15px;
padding-left: 15px;
}

div.scheduler div.col-1 .cl-new-booking {
width: calc(100% - 20px);
max-width: 480px;
margin: 15px 10px 5px;
}
}

@media only screen and (width >=960px) {
Expand Down Expand Up @@ -91,4 +97,8 @@ div.scheduler {
margin-bottom: 10px;
}

div.scheduler div.col-1 .cl-new-booking {
width: 265px;
margin-left: 5px;
}
}
6 changes: 2 additions & 4 deletions backend/src/components/VehicleScheduler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const VehicleScheduler = (
]

const dateBetween = new Date(query.end.getTime() - Math.ceil(query.end.getTime() - query.start.getTime()) / 2)
dateBetween.setHours(23, 59, 0, 0)
dateBetween.setHours(10, 0, 0, 0)

const payload: bookcarsTypes.GetBookingsPayload = {
suppliers,
Expand All @@ -62,8 +62,6 @@ const VehicleScheduler = (
},
user: (user && user._id) || undefined,
}
console.log(payload.filter?.dateBetween)
console.log(payload.filter?.to)

const data = await BookingService.getBookings(payload, 1, 10000)
const _data = data && data.length > 0 ? data[0] : { pageInfo: { totalRecord: 0 }, resultData: [] }
Expand Down Expand Up @@ -212,8 +210,8 @@ const VehicleScheduler = (
return (
<ReactScheduler
ref={schedulerRef}
locale={language === 'fr' ? fr : language === 'es' ? es : enUS}
view="month"
locale={language === 'fr' ? fr : language === 'es' ? es : enUS}
disableViewer
editable={false}
draggable={false}
Expand Down
5 changes: 5 additions & 0 deletions backend/src/pages/Scheduler.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from 'react'
import { Button } from '@mui/material'
import * as bookcarsTypes from ':bookcars-types'
import * as bookcarsHelper from ':bookcars-helper'
import { strings } from '@/lang/bookings'
import env from '@/config/env.config'
import * as helper from '@/common/helper'
import * as SupplierService from '@/services/SupplierService'
Expand Down Expand Up @@ -56,6 +58,9 @@ const Scheduler = () => {
<div className="col-1">
{leftPanel && (
<>
<Button variant="contained" className="btn-primary cl-new-booking" size="small" href="/create-booking">
{strings.NEW_BOOKING}
</Button>
{admin
&& (
<SupplierFilter
Expand Down

0 comments on commit a1e11f4

Please sign in to comment.