From c5099ce2e88f448e32c4b5a4e7e5319e91fe461e Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Sun, 16 Oct 2022 00:14:02 +0200 Subject: [PATCH] refactor: run formatter --- backend/src/auth/jobs/jobs.service.ts | 62 ++++++++++--------- .../src/share/guard/shareSecurity.guard.ts | 6 +- frontend/package.json | 2 +- frontend/src/components/Footer.tsx | 5 +- .../src/components/navBar/ActionAvatar.tsx | 2 +- frontend/src/components/share/FileList.tsx | 2 +- frontend/src/components/upload/FileList.tsx | 2 +- .../upload/showCreateUploadModal.tsx | 6 +- 8 files changed, 47 insertions(+), 40 deletions(-) diff --git a/backend/src/auth/jobs/jobs.service.ts b/backend/src/auth/jobs/jobs.service.ts index 58334d4..688d2f3 100644 --- a/backend/src/auth/jobs/jobs.service.ts +++ b/backend/src/auth/jobs/jobs.service.ts @@ -6,37 +6,39 @@ import * as moment from "moment"; @Injectable() export class JobsService { - constructor( - private prisma: PrismaService, - private fileService: FileService - ) { + constructor( + private prisma: PrismaService, + private fileService: FileService + ) {} + + @Cron("0 * * * *") + async deleteExpiredShares() { + const expiredShares = await this.prisma.share.findMany({ + where: { + // We want to remove only shares that have an expiration date less than the current date, but not 0 + AND: [ + { expiration: { lt: new Date() } }, + { expiration: { not: moment(0).toDate() } }, + ], + }, + }); + + for (const expiredShare of expiredShares) { + await this.prisma.share.delete({ + where: { id: expiredShare.id }, + }); + + await this.fileService.deleteAllFiles(expiredShare.id); } - @Cron("0 * * * *") - async deleteExpiredShares() { - const expiredShares = await this.prisma.share.findMany({ - where: { - // We want to remove only shares that have an expiration date less than the current date, but not 0 - AND: [{expiration: {lt: new Date()}}, {expiration: {not: moment(0).toDate()}}] - }, - }); + console.log(`job: deleted ${expiredShares.length} expired shares`); + } - for (const expiredShare of expiredShares) { - await this.prisma.share.delete({ - where: {id: expiredShare.id}, - }); - - await this.fileService.deleteAllFiles(expiredShare.id); - } - - console.log(`job: deleted ${expiredShares.length} expired shares`); - } - - @Cron("0 * * * *") - async deleteExpiredRefreshTokens() { - const expiredShares = await this.prisma.refreshToken.deleteMany({ - where: {expiresAt: {lt: new Date()}}, - }); - console.log(`job: deleted ${expiredShares.count} expired refresh tokens`); - } + @Cron("0 * * * *") + async deleteExpiredRefreshTokens() { + const expiredShares = await this.prisma.refreshToken.deleteMany({ + where: { expiresAt: { lt: new Date() } }, + }); + console.log(`job: deleted ${expiredShares.count} expired refresh tokens`); + } } diff --git a/backend/src/share/guard/shareSecurity.guard.ts b/backend/src/share/guard/shareSecurity.guard.ts index b768452..028689c 100644 --- a/backend/src/share/guard/shareSecurity.guard.ts +++ b/backend/src/share/guard/shareSecurity.guard.ts @@ -34,7 +34,11 @@ export class ShareSecurityGuard implements CanActivate { include: { security: true }, }); - if (!share || (moment().isAfter(share.expiration) && moment(share.expiration).unix() !== 0)) + if ( + !share || + (moment().isAfter(share.expiration) && + moment(share.expiration).unix() !== 0) + ) throw new NotFoundException("Share not found"); if (share.security?.password && !shareToken) diff --git a/frontend/package.json b/frontend/package.json index 4042ea7..fe0793f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,7 +6,7 @@ "build": "next build", "start": "dotenv next start", "lint": "next lint", - "format": "prettier --write \"src/**/*.ts\"" + "format": "prettier --write \"src/**/*.ts*\"" }, "dependencies": { "@emotion/react": "^11.10.4", diff --git a/frontend/src/components/Footer.tsx b/frontend/src/components/Footer.tsx index dc6eeb4..869e795 100644 --- a/frontend/src/components/Footer.tsx +++ b/frontend/src/components/Footer.tsx @@ -5,7 +5,10 @@ const Footer = () => {
- Made with 🖤 by Elias Schneider + Made with 🖤 by{" "} + + Elias Schneider +
diff --git a/frontend/src/components/navBar/ActionAvatar.tsx b/frontend/src/components/navBar/ActionAvatar.tsx index 867029c..2db5090 100644 --- a/frontend/src/components/navBar/ActionAvatar.tsx +++ b/frontend/src/components/navBar/ActionAvatar.tsx @@ -1,6 +1,6 @@ import { ActionIcon, Avatar, Menu } from "@mantine/core"; import { NextLink } from "@mantine/next"; -import { TbDoorExit, TbLink } from "react-icons/tb";; +import { TbDoorExit, TbLink } from "react-icons/tb"; import authService from "../../services/auth.service"; const ActionAvatar = () => { diff --git a/frontend/src/components/share/FileList.tsx b/frontend/src/components/share/FileList.tsx index 9cce244..8ffeef0 100644 --- a/frontend/src/components/share/FileList.tsx +++ b/frontend/src/components/share/FileList.tsx @@ -1,5 +1,5 @@ import { ActionIcon, Loader, Skeleton, Table } from "@mantine/core"; -import { TbCircleCheck, TbDownload } from "react-icons/tb";; +import { TbCircleCheck, TbDownload } from "react-icons/tb"; import shareService from "../../services/share.service"; import { byteStringToHumanSizeString } from "../../utils/math/byteStringToHumanSizeString.util"; diff --git a/frontend/src/components/upload/FileList.tsx b/frontend/src/components/upload/FileList.tsx index fb4c2a7..a1854e4 100644 --- a/frontend/src/components/upload/FileList.tsx +++ b/frontend/src/components/upload/FileList.tsx @@ -1,6 +1,6 @@ import { ActionIcon, Table } from "@mantine/core"; import { Dispatch, SetStateAction } from "react"; -import { TbTrash } from "react-icons/tb";; +import { TbTrash } from "react-icons/tb"; import { FileUpload } from "../../types/File.type"; import { byteStringToHumanSizeString } from "../../utils/math/byteStringToHumanSizeString.util"; import UploadProgressIndicator from "./UploadProgressIndicator"; diff --git a/frontend/src/components/upload/showCreateUploadModal.tsx b/frontend/src/components/upload/showCreateUploadModal.tsx index 86dab8d..e345ce1 100644 --- a/frontend/src/components/upload/showCreateUploadModal.tsx +++ b/frontend/src/components/upload/showCreateUploadModal.tsx @@ -8,14 +8,12 @@ const showCreateUploadModal = ( uploadCallback: ( id: string, expiration: string, - security: ShareSecurity, + security: ShareSecurity ) => void ) => { return modals.openModal({ title: Share, - children: ( - - ), + children: , }); };