Skip to content

Commit

Permalink
Add fully booked and coming soon flags, full to full and full to empt…
Browse files Browse the repository at this point in the history
…y fuel policies to mobile app
  • Loading branch information
aelassas committed Jan 22, 2025
1 parent 0be204e commit 94b5b22
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 66 deletions.
15 changes: 3 additions & 12 deletions api/src/controllers/carController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,25 +661,16 @@ export const getFrontendCars = async (req: Request, res: Response) => {
{ locations: pickupLocation },
{ type: { $in: carType } },
{ gearbox: { $in: gearbox } },
{ available: true },
],
}

if (!includeAlreadyBookedCars) {
$match.$and!.push({
$or: [
{ $and: [{ $or: [{ fullyBooked: false }, { fullyBooked: null }] }, { available: true }] },
{ $and: [{ $or: [{ fullyBooked: false }, { fullyBooked: null }] }, { available: false }] },
],
})
$match.$and!.push({ $or: [{ fullyBooked: false }, { fullyBooked: null }] })
}

if (!includeComingSoonCars) {
$match.$and!.push({
$or: [
{ $and: [{ $or: [{ comingSoon: false }, { comingSoon: null }] }, { available: true }] },
{ $and: [{ $or: [{ comingSoon: false }, { comingSoon: null }] }, { available: false }] },
],
})
$match.$and!.push({ $or: [{ comingSoon: false }, { comingSoon: null }] })
}

if (fuelPolicy) {
Expand Down
24 changes: 12 additions & 12 deletions backend/src/lang/cars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ const strings = new LocalizedStrings({
INCLUDED: 'Inclus',
AVAILABLE: 'Disponile',
UNAVAILABLE: 'Indisponible',
CAR_AVAILABLE: 'Disponible',
CAR_AVAILABLE_TOOLTIP: 'Cette voiture est disponible.',
CAR_UNAVAILABLE: 'Indisponible',
CAR_UNAVAILABLE_TOOLTIP: "Cette voiture n'est pas disponible.",
CAR_AVAILABLE: 'Répertoriée dans les résultats de recherche',
CAR_AVAILABLE_TOOLTIP: 'Cette voiture est eépertoriée dans les résultats de recherche.',
CAR_UNAVAILABLE: 'Non répertoriée dans les résultats de recherche',
CAR_UNAVAILABLE_TOOLTIP: "Cette voiture n'est pas répertoriée dans les résultats de recherche.",
VIEW_CAR: 'Voir cette voiture',
EMPTY_LIST: 'Pas de voitures.',
CANNOT_DELETE_CAR: 'Cette voiture ne peut pas être supprimée car elle est liée à des réservations. Vous pouvez cependant la rendre indisponible à la location en la modifiant.',
Expand Down Expand Up @@ -147,10 +147,10 @@ const strings = new LocalizedStrings({
INCLUDED: 'Included',
AVAILABLE: 'Available',
UNAVAILABLE: 'Unavailable',
CAR_AVAILABLE: 'Available',
CAR_AVAILABLE_TOOLTIP: 'This car is available.',
CAR_UNAVAILABLE: 'Unavailable',
CAR_UNAVAILABLE_TOOLTIP: 'This car is unavailable.',
CAR_AVAILABLE: 'Listed in search results',
CAR_AVAILABLE_TOOLTIP: 'This car is listed in search results.',
CAR_UNAVAILABLE: 'Not listed in search results',
CAR_UNAVAILABLE_TOOLTIP: 'This car is not listed in search results.',
VIEW_CAR: 'View this car',
EMPTY_LIST: 'No cars.',
CANNOT_DELETE_CAR: 'This car cannot be deleted because it is linked to bookings. However, you can make it unavailable for rental by modifying it.',
Expand Down Expand Up @@ -227,10 +227,10 @@ const strings = new LocalizedStrings({
INCLUDED: 'Incluido',
AVAILABLE: 'Disponible',
UNAVAILABLE: 'No disponible',
CAR_AVAILABLE: 'Disponible',
CAR_AVAILABLE_TOOLTIP: 'Este coche está disponible.',
CAR_UNAVAILABLE: 'No disponible',
CAR_UNAVAILABLE_TOOLTIP: 'Este coche no está disponible.',
CAR_AVAILABLE: 'Incluido en los resultados de búsqueda',
CAR_AVAILABLE_TOOLTIP: 'Este coche está incluido en los resultados de búsqueda.',
CAR_UNAVAILABLE: 'No incluido en los resultados de búsqueda',
CAR_UNAVAILABLE_TOOLTIP: 'Este coche no está incluido en los resultados de búsqueda.',
VIEW_CAR: 'Ver este coche',
EMPTY_LIST: 'No hay coches.',
CANNOT_DELETE_CAR: 'Este coche no se puede eliminar porque está vinculado a reservas. Sin embargo, puede hacerlo no disponible para alquilar modificándolo.',
Expand Down
6 changes: 3 additions & 3 deletions backend/src/lang/create-car.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const strings = new LocalizedStrings({
RECOMMENDED_IMAGE_SIZE: `Taille d'image recommandée : ${env.CAR_IMAGE_WIDTH}x${env.CAR_IMAGE_HEIGHT}`,
SUPPLIER: 'Fournisseur',
LOCATIONS: 'Lieux de prise en charge',
AVAILABLE: 'Disponible',
AVAILABLE: 'Répertoriée dans les résultats de recherche',
CAR_TYPE: 'Moteur',
DAILY_PRICE: 'Prix/jour',
DISCOUNTED_DAILY_PRICE: 'Prix discount/jour',
Expand Down Expand Up @@ -40,7 +40,7 @@ const strings = new LocalizedStrings({
RECOMMENDED_IMAGE_SIZE: `Recommended image size: ${env.CAR_IMAGE_WIDTH}x${env.CAR_IMAGE_HEIGHT}`,
SUPPLIER: 'Supplier',
LOCATIONS: 'Pick-up locations',
AVAILABLE: 'Available',
AVAILABLE: 'Listed in search results',
CAR_TYPE: 'Engine',
DAILY_PRICE: 'Daily Price',
DISCOUNTED_DAILY_PRICE: 'Discounted Daily Price',
Expand Down Expand Up @@ -70,7 +70,7 @@ const strings = new LocalizedStrings({
RECOMMENDED_IMAGE_SIZE: `Tamaño de imagen recomendado: ${env.CAR_IMAGE_WIDTH}x${env.CAR_IMAGE_HEIGHT}`,
SUPPLIER: 'Proveedor',
LOCATIONS: 'Lugares de recogida',
AVAILABLE: 'Disponible',
AVAILABLE: 'Incluido en los resultados de búsqueda',
CAR_TYPE: 'Motor',
DAILY_PRICE: 'Precio diario',
DISCOUNTED_DAILY_PRICE: 'Precio diario con descuento',
Expand Down
6 changes: 6 additions & 0 deletions mobile/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ export const getFuelPolicy = (type: string) => {
case bookcarsTypes.FuelPolicy.FreeTank:
return i18n.t('FUEL_POLICY_FREE_TANK')

case bookcarsTypes.FuelPolicy.FullToFull:
return i18n.t('FUEL_POLICY_FULL_TO_FULL')

case bookcarsTypes.FuelPolicy.FullToEmpty:
return i18n.t('FUEL_POLICY_FULL_TO_EMPTY')

default:
return ''
}
Expand Down
15 changes: 14 additions & 1 deletion mobile/components/Car.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ const Car = ({
fontSize: 13,
color: '#a1a1a1',
},
carInfo: {
fontSize: 13,
fontWeight: 'bold',
color: '#FD3446',
},
buttonContainer: {
alignItems: 'center',
justifyContent: 'center',
Expand Down Expand Up @@ -418,11 +423,19 @@ const Car = ({
<Text style={styles.priceSecondary}>{helper.getDays(days)}</Text>
<Text style={styles.pricePrimary}>{`${bookcarsHelper.formatPrice(totalPrice, currencySymbol, language)}`}</Text>
<Text style={styles.priceSecondary}>{`${i18n.t('PRICE_PER_DAY')} ${bookcarsHelper.formatPrice(totalPrice / days, currencySymbol, language)}`}</Text>

{
car.comingSoon ? (
<Text style={styles.carInfo}>{i18n.t('COMING_SOON')}</Text>
) : car.fullyBooked ? (
<Text style={styles.carInfo}>{i18n.t('FULLY_BOOKED')}</Text>
) : null
}
</View>
)}
</View>

{!hidePrice && from && to && pickupLocation && dropOffLocation && (
{!hidePrice && from && to && pickupLocation && dropOffLocation && car.available && !car.fullyBooked && !car.comingSoon && (
<View style={styles.buttonContainer}>
<Button
style={styles.button}
Expand Down
8 changes: 7 additions & 1 deletion mobile/components/CarList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ interface CarListProps {
footerComponent?: React.ReactElement
routeName?: 'Cars' | 'Checkout',
route: RouteProp<StackParams, keyof StackParams>
includeAlreadyBookedCars?: boolean
includeComingSoonCars?: boolean
onLoad?: bookcarsTypes.DataEvent<bookcarsTypes.Car>
}

Expand Down Expand Up @@ -66,7 +68,9 @@ const CarList = ({
footerComponent,
routeName,
// route,
onLoad
includeAlreadyBookedCars,
includeComingSoonCars,
onLoad,
}: CarListProps) => {
const [language, setLanguage] = useState(env.DEFAULT_LANGUAGE)
const [onScrollEnd, setOnScrollEnd] = useState(false)
Expand Down Expand Up @@ -123,6 +127,8 @@ const CarList = ({
mileage: _mileage,
fuelPolicy: _fuelPolicy,
deposit: _deposit,
includeAlreadyBookedCars,
includeComingSoonCars,
}

const data = await CarService.getCars(payload, _page, env.CARS_PAGE_SIZE)
Expand Down
66 changes: 58 additions & 8 deletions mobile/components/FuelPolicyFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const FuelPolicyFilter = ({
onChange
}: FuelPolicyFilterProps) => {
const [freeTank, setFreeTank] = useState(false)
const [likeForLike, setlikeForLike] = useState(false)
const [likeForLike, setLikeForLike] = useState(false)
const [fullToFull, setFullToFull] = useState(false)
const [fullToEmpty, setFullToEmpty] = useState(false)
const [values, setValues] = useState<bookcarsTypes.FuelPolicy[]>([])
const [allChecked, setAllChecked] = useState(false)

Expand All @@ -36,7 +38,7 @@ const FuelPolicyFilter = ({
if (checked) {
values.push(bookcarsTypes.FuelPolicy.FreeTank)

if (values.length === 2) {
if (values.length === allValues.length) {
setAllChecked(true)
}
} else {
Expand All @@ -55,11 +57,11 @@ const FuelPolicyFilter = ({
handleChange(values)
}

const onValueChangelikeForLike = (checked: boolean) => {
const onValueChangeLikeForLike = (checked: boolean) => {
if (checked) {
values.push(bookcarsTypes.FuelPolicy.LikeForLike)

if (values.length === 2) {
if (values.length === allValues.length) {
setAllChecked(true)
}
} else {
Expand All @@ -73,7 +75,53 @@ const FuelPolicyFilter = ({
}
}

setlikeForLike(checked)
setLikeForLike(checked)
setValues(values)
handleChange(values)
}

const onValueChangeFullToFull = (checked: boolean) => {
if (checked) {
values.push(bookcarsTypes.FuelPolicy.FullToFull)

if (values.length === allValues.length) {
setAllChecked(true)
}
} else {
values.splice(
values.findIndex((v) => v === bookcarsTypes.FuelPolicy.FullToFull),
1,
)

if (values.length === 0) {
setAllChecked(false)
}
}

setFullToFull(checked)
setValues(values)
handleChange(values)
}

const onValueChangeFullToEmpty = (checked: boolean) => {
if (checked) {
values.push(bookcarsTypes.FuelPolicy.FullToEmpty)

if (values.length === allValues.length) {
setAllChecked(true)
}
} else {
values.splice(
values.findIndex((v) => v === bookcarsTypes.FuelPolicy.FullToEmpty),
1,
)

if (values.length === 0) {
setAllChecked(false)
}
}

setFullToEmpty(checked)
setValues(values)
handleChange(values)
}
Expand All @@ -84,7 +132,9 @@ const FuelPolicyFilter = ({
<Accordion style={styles.accordion} title={i18n.t('FUEL_POLICY')}>
<View style={styles.contentContainer}>
<Switch style={styles.component} textStyle={styles.text} value={freeTank} label={i18n.t('FUEL_POLICY_FREE_TANK')} onValueChange={onValueChangeFreeTank} />
<Switch style={styles.component} textStyle={styles.text} value={likeForLike} label={i18n.t('FUEL_POLICY_LIKE_FOR_LIKE')} onValueChange={onValueChangelikeForLike} />
<Switch style={styles.component} textStyle={styles.text} value={likeForLike} label={i18n.t('FUEL_POLICY_LIKE_FOR_LIKE')} onValueChange={onValueChangeLikeForLike} />
<Switch style={styles.component} textStyle={styles.text} value={fullToFull} label={i18n.t('FUEL_POLICY_FULL_TO_FULL')} onValueChange={onValueChangeFullToFull} />
<Switch style={styles.component} textStyle={styles.text} value={fullToEmpty} label={i18n.t('FUEL_POLICY_FULL_TO_EMPTY')} onValueChange={onValueChangeFullToEmpty} />
</View>
<Link
style={styles.link}
Expand All @@ -93,13 +143,13 @@ const FuelPolicyFilter = ({
onPress={() => {
if (allChecked) {
setFreeTank(false)
setlikeForLike(false)
setLikeForLike(false)
setAllChecked(false)
setValues([])
} else {
const _values = allValues
setFreeTank(true)
setlikeForLike(true)
setLikeForLike(true)
setAllChecked(true)
setValues(_values)
handleChange(_values)
Expand Down
4 changes: 4 additions & 0 deletions mobile/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export const en = {
FUEL_POLICY: 'Fuel policy',
FUEL_POLICY_LIKE_FOR_LIKE: 'Like for Like',
FUEL_POLICY_FREE_TANK: 'Free tank',
FUEL_POLICY_FULL_TO_FULL: 'Full to Full',
FUEL_POLICY_FULL_TO_EMPTY: 'Full to Empty',
MILEAGE: 'Mileage',
MILEAGE_UNIT: 'KM/day',
UNLIMITED: 'Unlimited',
Expand Down Expand Up @@ -241,4 +243,6 @@ export const en = {
UPLOAD_FILE: 'Upload file...',
SHOW_FILTERS: 'Show filters',
HIDE_FILTERS: 'Hide filters',
COMING_SOON: 'Coming Soon',
FULLY_BOOKED: 'Fully Booked',
}
4 changes: 4 additions & 0 deletions mobile/lang/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export const es = {
FUEL_POLICY: 'Política de combustible',
FUEL_POLICY_LIKE_FOR_LIKE: 'Lleno/Lleno',
FUEL_POLICY_FREE_TANK: 'Tanque lleno incluido',
FUEL_POLICY_FULL_TO_FULL: 'Lleno/Lleno',
FUEL_POLICY_FULL_TO_EMPTY: 'Lleno/Vacío',
MILEAGE: 'Kilometraje',
MILEAGE_UNIT: 'KM/día',
UNLIMITED: 'Ilimitado',
Expand Down Expand Up @@ -241,4 +243,6 @@ export const es = {
UPLOAD_FILE: 'Subir archivo...',
SHOW_FILTERS: 'Mostrar filtros',
HIDE_FILTERS: 'Ocultar filtros',
COMING_SOON: 'Próximamente',
FULLY_BOOKED: 'Ya Reservado',
}
6 changes: 5 additions & 1 deletion mobile/lang/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ export const fr = {
GEARBOX_MANUAL_SHORT: 'M',
GEARBOX_AUTOMATIC_SHORT: 'A',
FUEL_POLICY: 'Politique carburant',
FUEL_POLICY_LIKE_FOR_LIKE: 'Plein/Plein',
FUEL_POLICY_LIKE_FOR_LIKE: 'Même niveau',
FUEL_POLICY_FREE_TANK: 'Plein inclus',
FUEL_POLICY_FULL_TO_FULL: 'Plein/Plein',
FUEL_POLICY_FULL_TO_EMPTY: 'Plein/Vide',
MILEAGE: 'Kilométrage',
MILEAGE_UNIT: 'KM/jour',
UNLIMITED: 'Illimité',
Expand Down Expand Up @@ -241,4 +243,6 @@ export const fr = {
UPLOAD_FILE: 'Charger un ficher...',
SHOW_FILTERS: 'Montrer les filtres',
HIDE_FILTERS: 'Cacher les filtres',
COMING_SOON: 'Bientôt Disponible',
FULLY_BOOKED: 'Déjà réservée',
}
Loading

0 comments on commit 94b5b22

Please sign in to comment.