Skip to content

Commit 98be7c6

Browse files
kostyshmfw78
authored andcommitted
chore: 🤖 added prettier code style fixes
1 parent f87cadb commit 98be7c6

File tree

6 files changed

+116
-46
lines changed

6 files changed

+116
-46
lines changed

‎src/controllers/FacilityController.ts‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,32 @@ import ApiError from '../exceptions/ApiError';
55
import { SpaceAvailabilityRepository } from '../repositories/SpaceAvailabilityRepository';
66

77
export class FacilityController {
8-
98
// Returns availability of the space
10-
getSpaceAvailability = async (req: Request, res: Response, next: NextFunction) => {
9+
getSpaceAvailability = async (
10+
req: Request,
11+
res: Response,
12+
next: NextFunction
13+
) => {
1114
try {
1215
const { facilityId, spaceId, date } = req.params;
1316

1417
const repository = new SpaceAvailabilityRepository(facilityId, spaceId);
15-
const numSpaces = await repository.getSpaceAvailabilityNumSpaces(date as AvailabilityDate);
18+
const numSpaces = await repository.getSpaceAvailabilityNumSpaces(
19+
date as AvailabilityDate
20+
);
1621

1722
return res.json({ numSpaces });
1823
} catch (e) {
1924
next(e);
2025
}
21-
}
26+
};
2227

2328
// Adds availability of the space by date
24-
createSpaceAvailability = async (req: Request, res: Response, next: NextFunction) => {
29+
createSpaceAvailability = async (
30+
req: Request,
31+
res: Response,
32+
next: NextFunction
33+
) => {
2534
try {
2635
const { facilityId, spaceId, date } = req.params;
2736
const { numSpaces } = req.body;
@@ -40,10 +49,14 @@ export class FacilityController {
4049
} catch (e) {
4150
next(e);
4251
}
43-
}
52+
};
4453

4554
// Adds/updates `default` availability of the space
46-
createDefaultSpaceAvailability = async (req: Request, res: Response, next: NextFunction) => {
55+
createDefaultSpaceAvailability = async (
56+
req: Request,
57+
res: Response,
58+
next: NextFunction
59+
) => {
4760
try {
4861
const { facilityId, spaceId } = req.params;
4962
const { numSpaces } = req.body;
@@ -55,7 +68,7 @@ export class FacilityController {
5568
} catch (e) {
5669
next(e);
5770
}
58-
}
71+
};
5972
}
6073

6174
export default new FacilityController();

‎src/repositories/FacilityRepository.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ export class FacilityRepository {
1313

1414
public async getFacilityIds(): Promise<string[]> {
1515
try {
16-
return await this.db.get<string, string[]>(
17-
'facilities',
18-
{ valueEncoding: 'json' }
19-
);
16+
return await this.db.get<string, string[]>('facilities', {
17+
valueEncoding: 'json'
18+
});
2019
} catch (e) {
2120
if (e.status !== 404) {
2221
throw e;
@@ -25,7 +24,10 @@ export class FacilityRepository {
2524
return [];
2625
}
2726

28-
public async createFacility(facilityId: string, facility: Facility): Promise<void> {
27+
public async createFacility(
28+
facilityId: string,
29+
facility: Facility
30+
): Promise<void> {
2931
const facilitySublevel = this.dbService.getFacilitySublevelDB(facilityId);
3032

3133
await facilitySublevel.put('metadata', facility);

‎src/repositories/SpaceAvailabilityRepository.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
1-
import DBService, { AvailabilityDate, AvailabilityItemKey, FacilityItemValues, LevelDefaultTyping } from '../services/DBService';
1+
import DBService, {
2+
AvailabilityDate,
3+
AvailabilityItemKey,
4+
FacilityItemValues,
5+
LevelDefaultTyping
6+
} from '../services/DBService';
27
import { AbstractLevel, AbstractSublevel } from 'abstract-level';
38
import { Availability } from '../proto/lpms';
49

510
export class SpaceAvailabilityRepository {
611
private dbService: DBService;
7-
private availableDB: AbstractSublevel<AbstractLevel<LevelDefaultTyping, string, FacilityItemValues>, LevelDefaultTyping, AvailabilityItemKey, Availability>;
12+
private availableDB: AbstractSublevel<
13+
AbstractLevel<LevelDefaultTyping, string, FacilityItemValues>,
14+
LevelDefaultTyping,
15+
AvailabilityItemKey,
16+
Availability
17+
>;
818

919
constructor(facilityId: string, spaceId: string) {
1020
this.dbService = DBService.getInstance();
11-
this.availableDB = this.dbService.getSpaceAvailabilityDB(facilityId, spaceId);
21+
this.availableDB = this.dbService.getSpaceAvailabilityDB(
22+
facilityId,
23+
spaceId
24+
);
1225
}
1326

14-
public async getSpaceAvailabilityNumSpaces(key: AvailabilityItemKey): Promise<number> {
27+
public async getSpaceAvailabilityNumSpaces(
28+
key: AvailabilityItemKey
29+
): Promise<number> {
1530
try {
1631
const availability: Availability = await this.availableDB.get(key);
1732
return availability.numSpaces;

‎src/router/index.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ export default router;
361361
* description: Some server error
362362
*/
363363
router.get(
364-
'/facility/:facilityId/space/:spaceId/availability/:date',
365-
authMiddleware,
366-
facilityController.getSpaceAvailability
364+
'/facility/:facilityId/space/:spaceId/availability/:date',
365+
authMiddleware,
366+
facilityController.getSpaceAvailability
367367
);
368368

369369
/**
@@ -422,7 +422,7 @@ router.get(
422422
* 500:
423423
* description: Some server error
424424
*/
425-
router.post(
425+
router.post(
426426
'/facility/:facilityId/space/:spaceId/availability/:date',
427427
authMiddleware,
428428
facilityController.createSpaceAvailability
@@ -478,7 +478,7 @@ router.get(
478478
* 500:
479479
* description: Some server error
480480
*/
481-
router.post(
481+
router.post(
482482
'/facility/:facilityId/space/:spaceId/availability',
483483
authMiddleware,
484484
facilityController.createDefaultSpaceAvailability

‎src/services/DBService.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ export default class DBService {
115115
}
116116

117117
public getSpaceAvailabilityDB(facilityId: string, itemId: string) {
118-
return this.getFacilityItemDB(facilityId, 'spaces', itemId).sublevel<AvailabilityItemKey, Availability>(
119-
'availability',
120-
{ valueEncoding: 'json' }
121-
);
118+
return this.getFacilityItemDB(facilityId, 'spaces', itemId).sublevel<
119+
AvailabilityItemKey,
120+
Availability
121+
>('availability', { valueEncoding: 'json' });
122122
}
123123
}

‎src/services/SpaceSearchService.ts‎

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)