Skip to content

Commit

Permalink
🔥 駐車場のstatus廃止
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsuyanh committed Mar 22, 2022
1 parent 3283feb commit 4a5b9dd
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 27 deletions.
2 changes: 1 addition & 1 deletion firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ service cloud.firestore {
}

match /posts/{post} {
allow list: if request.auth != null;
allow read: if request.auth != null;
allow create: if request.auth != null;
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ const parkingConverter = {
routeUrl: parking.routeUrl,
hourToOpen: parking.hourToOpen,
hourToClose: parking.hourToClose,
status: parking.status,
predicts: parking.predicts,
images: parking.images,
};
Expand All @@ -106,7 +105,6 @@ const parkingConverter = {
routeUrl: data.routeUrl,
hourToOpen: data.hourToOpen,
hourToClose: data.hourToClose,
status: data.status,
predicts: data.predicts,
images: data.images,
};
Expand Down
1 change: 0 additions & 1 deletion src/types/Parking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type Parking = {
routeUrl: string;
hourToOpen: number;
hourToClose: number;
status: string;
predicts: Predict[];
images: string[];
};
Expand Down
12 changes: 1 addition & 11 deletions src/utils/parking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const parkingBase: Parking = {
routeUrl: "https://...",
hourToOpen: 6,
hourToClose: 2,
status: "enable",
predicts: [
{ minutes: -360, ratio: 0.0 },
{ minutes: -330, ratio: 0.01 },
Expand Down Expand Up @@ -109,17 +108,8 @@ describe("parkingStatus", () => {
});
});

it("開場中だけど、ステータスが満車", () => {
const parkingFull = Object.assign(parkingBase, { status: "full" });
expect(parkingStatus(new Date("2021-11-28T12:00:00"), game, parkingFull)).toMatchObject({
state: "filled",
percent: 100,
fillMinutes: 0,
});
});

it("使用できない(予測情報などがあって開場時間中でも無視)", () => {
const parkingDisable = Object.assign(parkingBase, { status: "disable" });
const parkingDisable = Object.assign(parkingBase, { id: "panasonic" });
expect(parkingStatus(new Date("2021-11-28T12:00:00"), game, parkingDisable)).toMatchObject({
state: "disable",
percent: 0,
Expand Down
19 changes: 7 additions & 12 deletions src/utils/parking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const parkingStatus = (now: Date, game: Game, parking: Parking): ParkingS
const closeDate = new Date(game.finishAt.getTime());
closeDate.setHours(closeDate.getHours() + parking.hourToClose);

if (parking.status === "disable") {
if (!game.availableParkings.includes(parking.id)) {
// 未開放
return { state: "disable", percent: 0, fillMinutes: 0 };
} else if (now.getTime() < openDate.getTime()) {
Expand All @@ -19,19 +19,14 @@ export const parkingStatus = (now: Date, game: Game, parking: Parking): ParkingS
// 閉場後
return { state: "afterClosed", percent: 0, fillMinutes: 0 };
} else {
if (parking.status === "full") {
// 満車時
// 現状の埋まり具合と予測
const percent = suggestPercent(now, new Date(game.startAt.getTime()), parking.predicts);
if (percent >= 100) {
return { state: "filled", percent: 100, fillMinutes: 0 };
} else {
// 現状の埋まり具合と予測
const percent = suggestPercent(now, new Date(game.startAt.getTime()), parking.predicts);
if (percent >= 100) {
return { state: "filled", percent: 100, fillMinutes: 0 };
} else {
const fillDate = parkingFillDate(game, parking);
const fillMinutes = fillDate ? Math.ceil((fillDate?.getTime() - now.getTime()) / 60000) : 0;
return { state: "opened", percent: percent, fillMinutes: fillMinutes };
}
const fillDate = parkingFillDate(game, parking);
const fillMinutes = fillDate ? Math.ceil((fillDate?.getTime() - now.getTime()) / 60000) : 0;
return { state: "opened", percent: percent, fillMinutes: fillMinutes };
}
}
};
Expand Down

0 comments on commit 4a5b9dd

Please sign in to comment.