@@ -8,7 +8,8 @@ export default class SpaceSearchService {
88 static dbService = DBService . getInstance ( ) ;
99
1010 public static async check ( ask : Ask , facilityId : string ) : Promise < Space [ ] > {
11- const facilityDB = SpaceSearchService . dbService . getFacilitySublevelDB ( facilityId ) ;
11+ const facilityDB =
12+ SpaceSearchService . dbService . getFacilitySublevelDB ( facilityId ) ;
1213 let spacesIds ;
1314
1415 try {
@@ -24,7 +25,11 @@ export default class SpaceSearchService {
2425 const set = new Set ( ) ;
2526
2627 for ( const v of spacesIds ) {
27- const spaceDB = SpaceSearchService . dbService . getFacilityItemDB ( facilityId , 'spaces' , v ) ;
28+ const spaceDB = SpaceSearchService . dbService . getFacilityItemDB (
29+ facilityId ,
30+ 'spaces' ,
31+ v
32+ ) ;
2833 const space = await spaceDB . get ( 'metadata' ) ;
2934 set . add ( { space, id : v } ) ;
3035 }
@@ -40,36 +45,60 @@ export default class SpaceSearchService {
4045
4146 for ( const i of spaces ) {
4247 const space = i . space as Space ;
43- const numOfAdults = space . maxNumberOfAdultOccupantsOneof . oneofKind === 'maxNumberOfAdultOccupants'
44- ? space . maxNumberOfAdultOccupantsOneof . maxNumberOfAdultOccupants
45- : 0 ;
46-
47- const numOfChildren = space . maxNumberOfChildOccupantsOneof . oneofKind === 'maxNumberOfChildOccupants'
48- ? space . maxNumberOfChildOccupantsOneof . maxNumberOfChildOccupants
49- : 0 ;
48+ const numOfAdults =
49+ space . maxNumberOfAdultOccupantsOneof . oneofKind ===
50+ 'maxNumberOfAdultOccupants'
51+ ? space . maxNumberOfAdultOccupantsOneof . maxNumberOfAdultOccupants
52+ : 0 ;
53+
54+ const numOfChildren =
55+ space . maxNumberOfChildOccupantsOneof . oneofKind ===
56+ 'maxNumberOfChildOccupants'
57+ ? space . maxNumberOfChildOccupantsOneof . maxNumberOfChildOccupants
58+ : 0 ;
5059
5160 //check space capacity
52- if ( ! SpaceSearchService . checkSuitableQuantity ( numOfAdults , numOfChildren , ask . numPaxAdult , ask . numPaxChild ) ) {
61+ if (
62+ ! SpaceSearchService . checkSuitableQuantity (
63+ numOfAdults ,
64+ numOfChildren ,
65+ ask . numPaxAdult ,
66+ ask . numPaxChild
67+ )
68+ ) {
5369 continue ;
5470 }
5571
5672 //check dates is available
57- if ( await SpaceSearchService . checkAvailableDates ( i . id , facilityId , ask . checkIn , ask . checkOut , ask . numSpacesReq ) ) {
73+ if (
74+ await SpaceSearchService . checkAvailableDates (
75+ i . id ,
76+ facilityId ,
77+ ask . checkIn ,
78+ ask . checkOut ,
79+ ask . numSpacesReq
80+ )
81+ ) {
5882 needed . add ( space ) ;
5983 }
6084 }
6185
6286 return Array . from ( needed ) ;
6387 }
6488
65- private static checkSuitableQuantity ( spaceGuestsCount , spaceChildrenCount , guestCount , childrenCount ) {
89+ private static checkSuitableQuantity (
90+ spaceGuestsCount ,
91+ spaceChildrenCount ,
92+ guestCount ,
93+ childrenCount
94+ ) {
6695 const guestCheck = spaceGuestsCount - guestCount ;
6796
6897 if ( guestCheck < 0 ) {
6998 return false ;
7099 }
71100 //if there is a place left from an adult, we give it to a child
72- const childrenCheck = ( spaceChildrenCount + guestCheck ) - childrenCount ;
101+ const childrenCheck = spaceChildrenCount + guestCheck - childrenCount ;
73102
74103 if ( childrenCheck < 0 ) {
75104 return false ;
@@ -83,19 +112,30 @@ export default class SpaceSearchService {
83112 return true ;
84113 }
85114
86- private static async checkAvailableDates ( spaceId , facilityId , checkIn , checkOut , spacesRequired ) {
87- const availabilityRepository = new SpaceAvailabilityRepository ( facilityId , spaceId ) ;
88-
89- const defaultAvailable = await availabilityRepository . getSpaceAvailabilityNumSpaces ( 'default' ) ;
115+ private static async checkAvailableDates (
116+ spaceId ,
117+ facilityId ,
118+ checkIn ,
119+ checkOut ,
120+ spacesRequired
121+ ) {
122+ const availabilityRepository = new SpaceAvailabilityRepository (
123+ facilityId ,
124+ spaceId
125+ ) ;
126+
127+ const defaultAvailable =
128+ await availabilityRepository . getSpaceAvailabilityNumSpaces ( 'default' ) ;
90129
91130 let from = DateTime . fromObject ( checkIn ) ;
92131 const to = DateTime . fromObject ( checkOut ) ;
93132
94133 while ( from <= to ) {
95134 try {
96- const dailyBooks = await availabilityRepository . getSpaceAvailabilityNumSpaces (
97- from . toFormat ( 'yyyy-MM-dd' ) as AvailabilityDate
98- ) ;
135+ const dailyBooks =
136+ await availabilityRepository . getSpaceAvailabilityNumSpaces (
137+ from . toFormat ( 'yyyy-MM-dd' ) as AvailabilityDate
138+ ) ;
99139
100140 if ( defaultAvailable - dailyBooks < spacesRequired ) {
101141 return false ;
0 commit comments