Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

비활성화된 사물함에 대한 대여 불가 처리 #41

Merged
merged 1 commit into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/server/src/config/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ function toLockerSubsectionData(subsection: LockerSubsection): LockerSubsectionD
function fromLockerSectionData(data: LockerSectionData): LockerSection {
return {
subsections: data.s.L.map((subsectionData) => fromLockerSubsectionData(subsectionData.M)),
disabled: data.d.L.map((disabled) => disabled.S),
disabled: data.d.NS.map((disabled) => parseInt(disabled)),
height: parseInt(data.h?.N ?? '0')
};
}

function toLockerSectionData(section: LockerSection): LockerSectionData {
return {
s: { L: section.subsections.map((ss) => ({ M: toLockerSubsectionData(ss) })) },
d: { L: section.disabled.map((d) => ({ S: d })) },
d: { NS: section.disabled.map((d) => `${d}`) },
h: { N: `${section.height}` }
};
}
Expand Down
24 changes: 10 additions & 14 deletions packages/server/src/util/locker.ts
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');
}
}
4 changes: 2 additions & 2 deletions packages/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ type BuildingData = {

type LockerSection = {
subsections: LockerSubsection[];
disabled: string[];
disabled: number[];
height: number;
};

type LockerSectionData = {
s: { L: { M: LockerSubsectionData }[] };
d: { L: { S: string }[] };
d: { NS: string[] };
h: { N: string };
};

Expand Down