forked from TEAM-MAT/lockerweb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from EATSTEAK/feat/locker_disabled
비활성화된 사물함에 대한 대여 불가 처리
- Loading branch information
Showing
3 changed files
with
14 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
export function isValidLocker( | ||
config: ServiceConfig, | ||
lockerId: string, | ||
department: string | ||
) { | ||
export function isValidLocker(config: ServiceConfig, lockerId: string, department: string) { | ||
const buildings = config.buildings; | ||
const parsedLockerId = lockerId.split('-'); | ||
const buildingNum = parsedLockerId[0]; | ||
const lockerFloor = parsedLockerId[1]; | ||
const lockerSection = parsedLockerId[2].substr(0, 1); | ||
const lockerSectionNum = parseInt(parsedLockerId[2].substr(1)); | ||
const selectedSections = buildings[buildingNum]?.lockers[lockerFloor]?.[lockerSection]?.subsections; | ||
const selectedSection = buildings[buildingNum]?.lockers[lockerFloor]?.[lockerSection]; | ||
const selectedSubsections = selectedSection?.subsections; | ||
if (parsedLockerId.length !== 3) return false; | ||
if (!selectedSections) return false; | ||
const section = selectedSections.find( | ||
if (!selectedSubsections) return false; | ||
const section = selectedSubsections.find( | ||
(sect) => | ||
sect.range[0] <= lockerSectionNum && | ||
sect.range[1] >= lockerSectionNum && | ||
!selectedSection.disabled.includes(lockerSectionNum) && | ||
(department === undefined || department === sect.department) | ||
); | ||
return section !== undefined; | ||
} | ||
|
||
export function getLockerDepartment( | ||
config: ServiceConfig, | ||
lockerId: string | ||
) { | ||
export function getLockerDepartment(config: ServiceConfig, lockerId: string) { | ||
const buildings = config.buildings; | ||
const parsedLockerId = lockerId.split('-'); | ||
const buildingNum = parsedLockerId[0]; | ||
const lockerFloor = parsedLockerId[1]; | ||
const lockerSection = parsedLockerId[2].substr(0, 1); | ||
const lockerSectionNum = parseInt(parsedLockerId[2].substr(1)); | ||
const selectedSections = buildings[buildingNum]?.lockers[lockerFloor]?.[lockerSection]?.subsections; | ||
const selectedSections = | ||
buildings[buildingNum]?.lockers[lockerFloor]?.[lockerSection]?.subsections; | ||
if (parsedLockerId.length !== 3) throw new Error('Given locker is not valid'); | ||
if (!selectedSections) Error('Given locker is not valid'); | ||
const section = selectedSections.find( | ||
(sect) => sect.range[0] <= lockerSectionNum && sect.range[1] >= lockerSectionNum | ||
); | ||
if (section) return section.department; | ||
else throw new Error('Given locker is not valid'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters