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

目標を完了した時にtasksを削除するように修正 #156

Merged
merged 1 commit into from
Jan 11, 2025
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
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
Loading