mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 21:35:19 +00:00
(squash) init
feat: filters, settings, backups fix: ts compile errors feat: new dashboard, webp previews and settings feat: use webp for pdfs feat: use webp fix: analyze resets old data fix: switch to corsproxy fix: switch to free cors fix: max upload limit fix: currency conversion feat: transaction export fix: currency conversion feat: refactor settings actions feat: new loader feat: README + LICENSE doc: update readme doc: update readme doc: update readme doc: update screenshots ci: bump prisma
This commit is contained in:
70
data/files.ts
Normal file
70
data/files.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
"use server"
|
||||
|
||||
import { prisma } from "@/lib/db"
|
||||
import { unlink } from "fs/promises"
|
||||
import path from "path"
|
||||
import { cache } from "react"
|
||||
import { getTransactionById } from "./transactions"
|
||||
|
||||
export const getUnsortedFiles = cache(async () => {
|
||||
return await prisma.file.findMany({
|
||||
where: {
|
||||
isReviewed: false,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
export const getUnsortedFilesCount = cache(async () => {
|
||||
return await prisma.file.count({
|
||||
where: {
|
||||
isReviewed: false,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
export const getFileById = cache(async (id: string) => {
|
||||
return await prisma.file.findFirst({
|
||||
where: { id },
|
||||
})
|
||||
})
|
||||
|
||||
export const getFilesByTransactionId = cache(async (id: string) => {
|
||||
const transaction = await getTransactionById(id)
|
||||
if (transaction && transaction.files) {
|
||||
return await prisma.file.findMany({
|
||||
where: {
|
||||
id: {
|
||||
in: transaction.files as string[],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
return []
|
||||
})
|
||||
|
||||
export const createFile = async (data: any) => {
|
||||
return await prisma.file.create({
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
export const updateFile = async (id: string, data: any) => {
|
||||
return await prisma.file.update({
|
||||
where: { id },
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteFile = async (id: string) => {
|
||||
const file = await getFileById(id)
|
||||
if (file) {
|
||||
await unlink(path.resolve(file.path))
|
||||
|
||||
return await prisma.file.delete({
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user