--- template/app/src/file-upload/fileUploading.ts +++ opensaas-sh/app/src/file-upload/fileUploading.ts @@ -1,4 +1,6 @@ +import { PrismaClient } from "@prisma/client"; import axios from "axios"; +import type { User } from "wasp/entities"; import { ALLOWED_FILE_TYPES, MAX_FILE_SIZE_BYTES } from "./validation"; type AllowedFileTypes = (typeof ALLOWED_FILE_TYPES)[number]; @@ -58,3 +60,23 @@ function isFileWithAllowedFileType(file: File): file is FileWithValidType { return ALLOWED_FILE_TYPES.includes(file.type as AllowedFileTypes); } + +export async function checkIfUserHasReachedFileUploadLimit({ + userId, + prismaFileDelegate, +}: { + userId: User["id"]; + prismaFileDelegate: PrismaClient["file"]; +}) { + const numberOfFilesByUser = await prismaFileDelegate.count({ + where: { + user: { + id: userId, + }, + }, + }); + if (numberOfFilesByUser >= 2) { + return true; + } + return false; +}