feat: bugfixes, spedup, bulk actions,

This commit is contained in:
Vasily Zubarev
2025-03-17 18:36:25 +01:00
parent b27f07043e
commit 14967e1c85
34 changed files with 433 additions and 225 deletions

View File

@@ -40,6 +40,9 @@ export const getFilesByTransactionId = cache(async (id: string) => {
in: transaction.files as string[],
},
},
orderBy: {
createdAt: "asc",
},
})
}
return []

View File

@@ -2,11 +2,7 @@ import { prisma } from "@/lib/db"
import { calcTotalPerCurrency } from "@/lib/stats"
import { Prisma } from "@prisma/client"
import { cache } from "react"
export type StatsFilters = {
dateFrom?: string
dateTo?: string
}
import { TransactionFilters } from "./transactions"
export type DashboardStats = {
totalIncomePerCurrency: Record<string, number>
@@ -15,7 +11,7 @@ export type DashboardStats = {
invoicesProcessed: number
}
export const getDashboardStats = cache(async (filters: StatsFilters = {}): Promise<DashboardStats> => {
export const getDashboardStats = cache(async (filters: TransactionFilters = {}): Promise<DashboardStats> => {
const where: Prisma.TransactionWhereInput = {}
if (filters.dateFrom || filters.dateTo) {
@@ -51,7 +47,7 @@ export type ProjectStats = {
invoicesProcessed: number
}
export const getProjectStats = cache(async (projectId: string, filters: StatsFilters = {}) => {
export const getProjectStats = cache(async (projectId: string, filters: TransactionFilters = {}) => {
const where: Prisma.TransactionWhereInput = {
projectCode: projectId,
}

View File

@@ -120,6 +120,12 @@ export const deleteTransaction = async (id: string): Promise<Transaction | undef
}
}
export const bulkDeleteTransactions = async (ids: string[]) => {
return await prisma.transaction.deleteMany({
where: { id: { in: ids } },
})
}
const splitTransactionDataExtraFields = async (
data: TransactionData
): Promise<{ standard: TransactionData; extra: Prisma.InputJsonValue }> => {