Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

fix: Useが残っている洗濯機を使用開始した際の問題を修正 #82

Merged
merged 3 commits into from
Oct 6, 2023
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
30 changes: 29 additions & 1 deletion app/routes/api.v1.laundry.$id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { pushMessage } from "~/firebase/messageServices.server";
import { getServiceAccount } from "~/firebase/serviceAccount.server";
import { getLaundryById, updateLaundry } from "~/models/laundry.server";
import { Notification } from "~/firebase/messageServices.server";
import { updateUse } from "~/models/use.server";
import {
deleteUseById,
getUseByLaundryId,
updateUse,
} from "~/models/use.server";

type LaundryStatusAPI = {
status: string;
Expand Down Expand Up @@ -79,5 +83,29 @@ export const action = async ({
});
}

// 洗濯開始
if (!laundry.running && result.running) {
const use = await getUseByLaundryId(laundry.id);
if (use?.endAt) {
await deleteUseById(use.id);
} else if (use) {
return json({}, 423);
}

if (use?.account?.messageToken) {
await pushMessage(
use.account.messageToken,
{
title: "洗濯回収のお知らせ",
body: `${laundry.room?.place}の洗濯機で、あなたの洗濯物が取り出されました。`,
},
{
projectId: env.FIREBASE_PROJECT_ID,
serviceAccount: getServiceAccount(env),
}
);
}
}

return json({}, 200);
};
10 changes: 6 additions & 4 deletions app/routes/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ export default function Home() {
if (user?.email == null) {
return;
}
submitUses({
accountEmail: user.email,
});
}, [user]);
if (uses == null || revalidator.state === "loading") {
submitUses({
accountEmail: user.email,
});
}
}, [user, revalidator.state]);

useEffect(() => {
const onFocus = revalidator.revalidate;
Expand Down