Skip to content

Commit

Permalink
Merge pull request #156 from MurakawaTakuya/fix/155-fix-delete-tasks-…
Browse files Browse the repository at this point in the history
…on-post

目標を完了した時にtasksを削除するように修正
  • Loading branch information
MurakawaTakuya authored Jan 11, 2025
2 parents b260dba + 66405a4 commit 56ac1b7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
1 change: 0 additions & 1 deletion functions/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module.exports = {
parserOptions: {
project: [
"tsconfig.json",
"tsconfig.functions.json",
"functions/tsconfig.json",
"functions/tsconfig.functions.json",
],
Expand Down
44 changes: 22 additions & 22 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/tasks": "^5.5.1",
"@google-cloud/tasks": "^5.5.2",
"@types/multer": "^1.4.12",
"express": "^4.21.2",
"express-rate-limit": "^7.4.1",
"express-rate-limit": "^7.5.0",
"firebase-admin": "^12.7.0",
"firebase-functions": "^6.1.1",
"firebase-functions": "^6.2.0",
"helmet": "^8.0.0",
"multer": "^1.4.5-lts.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"concurrently": "^9.1.0",
"concurrently": "^9.1.2",
"eslint": "^8.57.1",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-unused-imports": "^4.1.4",
"firebase-functions-test": "^3.1.0",
"firebase-functions-test": "^3.4.0",
"typescript": "^4.9.0"
},
"private": true
Expand Down
11 changes: 9 additions & 2 deletions functions/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { logger } from "firebase-functions";
import {
onDocumentCreated,
onDocumentDeleted,
onDocumentUpdated,
} from "firebase-functions/v2/firestore";

const tasksClient = new CloudTasksClient();
Expand Down Expand Up @@ -67,6 +68,7 @@ export const createTasksOnGoalCreate = onDocumentCreated(
}
);

// 目標を削除した時にtasksから通知予定を削除する
export const deleteTasksOnGoalDelete = onDocumentDeleted(
{ region: region, document: "goal/{goalId}" },
async (event) => {
Expand Down Expand Up @@ -96,10 +98,11 @@ export const deleteTasksOnGoalDelete = onDocumentDeleted(
}
);

export const deleteTasksOnPostCreate = onDocumentCreated(
// 目標を完了した時にtasksから通知予定を削除する
export const deleteTasksOnPostCreate = onDocumentUpdated(
{
region: region,
document: "goal/{goalId}/posts/{postId}",
document: "goal/{goalId}",
},
async (event) => {
if (process.env.NODE_ENV !== "production") {
Expand All @@ -116,6 +119,10 @@ export const deleteTasksOnPostCreate = onDocumentCreated(
return;
}

if (event.data.after.data().post !== null) {
return;
}

try {
const goalId = event.params.goalId;
const queuePath = tasksClient.queuePath(projectId, region, queue);
Expand Down

0 comments on commit 56ac1b7

Please sign in to comment.