From 3bc0a65bd6ed1bc8198e0b2dd89d6ed09570963e Mon Sep 17 00:00:00 2001 From: Tawnee Date: Wed, 22 May 2024 08:54:00 -0600 Subject: [PATCH 1/2] enable rewardable delete in cron --- scripts/puzzleCleanup.ts | 43 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/scripts/puzzleCleanup.ts b/scripts/puzzleCleanup.ts index ec7377bf4..59db83d8c 100644 --- a/scripts/puzzleCleanup.ts +++ b/scripts/puzzleCleanup.ts @@ -1,29 +1,28 @@ import { db } from 'api/src/lib/db' export default async () => { - const test = await db.rewardable.findFirst() - console.log('test: ', test?.id) + const twoWeeksAgo = new Date(Date.now() - 12096e5) - // const deletedPuzzleIds = await db.rewardable.findMany({ - // where: { - // trashedAt: { - // lte: new Date(Date.now() - 12096e5), - // }, - // }, - // select: { - // id: true, - // }, - // }) + const deletedPuzzleIds = await db.rewardable.findMany({ + where: { + trashedAt: { + lte: twoWeeksAgo, + }, + }, + select: { + id: true, + }, + }) - // if (deletedPuzzleIds.length) { - // await db.rewardable.deleteMany({ - // where: { - // trashedAt: { - // lte: new Date(Date.now() - 12096e5), - // }, - // }, - // }) + if (deletedPuzzleIds.length) { + await db.rewardable.deleteMany({ + where: { + trashedAt: { + lte: twoWeeksAgo, + }, + }, + }) - // console.info('Trashed puzzles: ', deletedPuzzleIds) - // } + console.info('Trashed puzzles: ', deletedPuzzleIds) + } } From c5fe021a5bba658404044d5e35a9ea3e7fd2db2f Mon Sep 17 00:00:00 2001 From: Tawnee Date: Fri, 31 May 2024 11:23:12 -0600 Subject: [PATCH 2/2] use date-fns --- package.json | 1 + scripts/puzzleCleanup.ts | 3 ++- yarn.lock | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f73ffea1..1e017b763 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ }, "packageManager": "yarn@3.5.1", "dependencies": { + "date-fns": "^3.6.0", "discord-economy-super": "^1.7.6", "jest-watch-typeahead": "^2.2.2", "lodash": "^4.17.21", diff --git a/scripts/puzzleCleanup.ts b/scripts/puzzleCleanup.ts index 59db83d8c..fd97c2b95 100644 --- a/scripts/puzzleCleanup.ts +++ b/scripts/puzzleCleanup.ts @@ -1,7 +1,8 @@ import { db } from 'api/src/lib/db' +import { sub } from 'date-fns/sub' export default async () => { - const twoWeeksAgo = new Date(Date.now() - 12096e5) + const twoWeeksAgo = sub(new Date(), { weeks: 2 }) const deletedPuzzleIds = await db.rewardable.findMany({ where: { diff --git a/yarn.lock b/yarn.lock index 7783f59f5..be03b6265 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17269,6 +17269,13 @@ __metadata: languageName: node linkType: hard +"date-fns@npm:^3.6.0": + version: 3.6.0 + resolution: "date-fns@npm:3.6.0" + checksum: 0b5fb981590ef2f8e5a3ba6cd6d77faece0ea7f7158948f2eaae7bbb7c80a8f63ae30b01236c2923cf89bb3719c33aeb150c715ea4fe4e86e37dcf06bed42fb6 + languageName: node + linkType: hard + "dayjs@npm:^1.10.4": version: 1.11.7 resolution: "dayjs@npm:1.11.7" @@ -30067,6 +30074,7 @@ __metadata: "@redwoodjs/auth-clerk-setup": 6.3.2 "@redwoodjs/cli-storybook": 6.3.2 "@redwoodjs/core": 6.3.2 + date-fns: ^3.6.0 discord-economy-super: ^1.7.6 jest-watch-typeahead: ^2.2.2 lodash: ^4.17.21