Skip to content

Commit

Permalink
fixup! 目標完了時にCloud Tasksの通知が削除されない問題を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
MurakawaTakuya committed Jan 28, 2025
1 parent 944458b commit c1762fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const firestore = onRequest({ region: region }, async (req, res) => {
export {
createTasksOnGoalCreate,
deleteTasksOnGoalDelete,
updateTasksOnPostUpdate as deleteTasksOnPostCreate,
updateTasksOnPostUpdate,
} from "./tasks";

// テスト用API
Expand Down
8 changes: 4 additions & 4 deletions functions/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const region = "asia-northeast1";
const queue = "deadline-notification-queue";
const marginTime = 10;

// TODO: タスク名の後ろに日時の値をつけて一意にする
// queuePath, postData, etaを受け取り、タスクを作成
const createTask = async (
queuePath: string,
postData: { goalId: string; marginTime: number },
Expand Down Expand Up @@ -126,13 +126,11 @@ export const updateTasksOnPostUpdate = onDocumentUpdated(
return;
}

logger.debug("Before:", event.data.before.data());
logger.debug("After:", event.data.after.data());

if (
event.data.before.data().post === null &&
event.data.after.data().post !== null
) {
// 目標を完了(完了投稿を作成)した場合
// null -> post に変更された場合はタスクを削除
try {
const goalId = event.params.goalId;
Expand All @@ -145,7 +143,9 @@ export const updateTasksOnPostUpdate = onDocumentUpdated(
event.data.before.data().post !== null &&
event.data.after.data().post === null
) {
// 完了投稿を削除した場合
// post -> null に変更された場合はタスクを作成(deadlineが今よりも後の場合のみ)

if (
event.data.after.data().deadline.toDate().getTime() <=
new Date().getTime()
Expand Down

0 comments on commit c1762fa

Please sign in to comment.