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 ec7377bf4..fd97c2b95 100644 --- a/scripts/puzzleCleanup.ts +++ b/scripts/puzzleCleanup.ts @@ -1,29 +1,29 @@ import { db } from 'api/src/lib/db' +import { sub } from 'date-fns/sub' export default async () => { - const test = await db.rewardable.findFirst() - console.log('test: ', test?.id) + const twoWeeksAgo = sub(new Date(), { weeks: 2 }) - // 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) + } } 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