Skip to content

Commit

Permalink
refactor(mobile): change Accomodation class to factory function
Browse files Browse the repository at this point in the history
  • Loading branch information
weronikaolejniczak committed May 23, 2024
1 parent 74fc200 commit 2bf2fc3
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 73 deletions.
78 changes: 40 additions & 38 deletions apps/mobile/src/actions/accommodationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from 'axios';
import { FIREBASE_URL } from 'react-native-config';

import Accommodation from 'models/Accommodation';
import Accomodation from 'models/Accommodation';

export const SET_ACCOMMODATION = 'SET_ACCOMMODATION';
export const CREATE_ACCOMMODATION = 'CREATE_ACCOMMODATION';
Expand Down Expand Up @@ -71,23 +72,24 @@ export const fetchAccommodationRequest = (tripId: string) => {
const loadedAccommodation = [];
for (const key in accommodation) {
loadedAccommodation.push(
new Accommodation(
key,
accommodation[key].amenities,
accommodation[key].breakfast,
accommodation[key].checkInExtra,
accommodation[key].checkInHours,
accommodation[key].checkOutHours,
accommodation[key].creditCardPaymentPossible,
accommodation[key].description,
accommodation[key].frontDesk24H,
accommodation[key].image,
accommodation[key].location,
accommodation[key].name,
accommodation[key].phone,
accommodation[key].reservationDetails,
accommodation[key].PDF,
),
Accomodation({
PDF: accommodation[key].PDF,
amenities: accommodation[key].amenities,
breakfast: accommodation[key].breakfast,
checkInExtra: accommodation[key].checkInExtra,
checkInHours: accommodation[key].checkInHours,
checkOutHours: accommodation[key].checkOutHours,
creditCardPaymentPossible:
accommodation[key].creditCardPaymentPossible,
description: accommodation[key].description,
frontDesk24H: accommodation[key].frontDesk24H,
id: key,
image: accommodation[key].image,
location: accommodation[key].location,
name: accommodation[key].name,
phone: accommodation[key].phone,
reservationDetails: accommodation[key].reservationDetails,
}),
);
}

Expand Down Expand Up @@ -166,23 +168,23 @@ export const createAccommodationRequest = (
.then((data) => {
const accommodationId = data[0].name;
const requestConfig = JSON.parse(data[1]);
const newAccommodation = new Accommodation(
accommodationId,
requestConfig.amenities,
requestConfig.breakfast,
requestConfig.checkInExtra,
requestConfig.checkInHours,
requestConfig.checkOutHours,
requestConfig.creditCardPaymentPossible,
requestConfig.description,
requestConfig.frontDesk24H,
requestConfig.image,
requestConfig.location,
requestConfig.name,
requestConfig.phone,
requestConfig.reservationDetails,
requestConfig.PDF,
);
const newAccommodation = Accommodation({
PDF: requestConfig.PDF,
amenities: requestConfig.amenities,
breakfast: requestConfig.breakfast,
checkInExtra: requestConfig.checkInExtra,
checkInHours: requestConfig.checkInHours,
checkOutHours: requestConfig.checkOutHours,
creditCardPaymentPossible: requestConfig.creditCardPaymentPossible,
description: requestConfig.description,
frontDesk24H: requestConfig.frontDesk24H,
id: accommodationId,
image: requestConfig.image,
location: requestConfig.location,
name: requestConfig.name,
phone: requestConfig.phone,
reservationDetails: requestConfig.reservationDetails,
});
dispatch(createAccommodation(tripId, newAccommodation));
})
.catch(() => {
Expand Down Expand Up @@ -235,8 +237,8 @@ export const editAccommodationRequest = (
)

.then(() => {
const updatedAccommodation = new Accommodation(
accommodationId,
const updatedAccommodation = Accommodation({
PDF,
amenities,
breakfast,
checkInExtra,
Expand All @@ -245,13 +247,13 @@ export const editAccommodationRequest = (
creditCardPaymentPossible,
description,
frontDesk24H,
id: accommodationId,
image,
location,
name,
phone,
reservationDetails,
PDF,
);
});
dispatch(
editAccommodation(tripId, updatedAccommodation, accommodationId),
);
Expand Down
86 changes: 51 additions & 35 deletions apps/mobile/src/models/Accommodation.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
class Accommodation {
constructor(
id,
amenities,
breakfast,
checkInExtra,
checkInHours,
checkOutHours,
creditCardPaymentPossible,
description,
frontDesk24H,
image,
location,
name,
phone,
reservationDetails,
PDF,
) {
this.id = id;
this.amenities = amenities;
this.breakfast = breakfast;
this.checkInExtra = checkInExtra;
this.checkInHours = checkInHours;
this.checkOutHours = checkOutHours;
this.creditCardPaymentPossible = creditCardPaymentPossible;
this.description = description;
this.frontDesk24H = frontDesk24H;
this.image = image;
this.location = location;
this.name = name;
this.phone = phone;
this.reservationDetails = reservationDetails;
this.PDF = PDF;
}
interface AccommodationParams {
id: string;
amenities: string[];
breakfast: boolean;
checkInExtra: boolean;
checkInHours: string;
checkOutHours: string;
creditCardPaymentPossible: boolean;
description: string;
frontDesk24H: boolean;
image: string;
location: string;
name: string;
phone: string;
reservationDetails: string;
PDF: string;
}

module.exports = Accommodation;
const Accomodation = ({
id,
amenities,
breakfast,
checkInExtra,
checkInHours,
checkOutHours,
creditCardPaymentPossible,
description,
frontDesk24H,
image,
location,
name,
phone,
reservationDetails,
PDF,
}: AccommodationParams) => ({
id,
amenities,
breakfast,
checkInExtra,
checkInHours,
checkOutHours,
creditCardPaymentPossible,
description,
frontDesk24H,
image,
location,
name,
phone,
reservationDetails,
PDF,
});

export default Accomodation;

0 comments on commit 2bf2fc3

Please sign in to comment.