fix: paginate import history and report
This commit is contained in:
29
server/db.ts
29
server/db.ts
@@ -571,10 +571,15 @@ export async function getAllImportLogs(): Promise<ImportLog[]> {
|
||||
* les paramètres sensibles de messagerie. L'administrateur peut ainsi relier
|
||||
* chaque import à son compte, fichier source et déclencheur.
|
||||
*/
|
||||
export async function getImportLogsWithDetailsByUser(userId: number) {
|
||||
export type ImportLogPageOptions = {
|
||||
limit: number;
|
||||
offset: number;
|
||||
};
|
||||
|
||||
export async function getImportLogsWithDetailsByUser(userId: number, options: ImportLogPageOptions) {
|
||||
const db = await getDb();
|
||||
if (!db) return [];
|
||||
return db.select({
|
||||
if (!db) return { items: [], total: 0 };
|
||||
const items = await db.select({
|
||||
...getTableColumns(importLogs),
|
||||
userName: users.name,
|
||||
userEmail: users.email,
|
||||
@@ -585,13 +590,17 @@ export async function getImportLogsWithDetailsByUser(userId: number) {
|
||||
.leftJoin(users, eq(importLogs.userId, users.id))
|
||||
.leftJoin(sourceFiles, eq(importLogs.sourceFileId, sourceFiles.id))
|
||||
.where(eq(importLogs.userId, userId))
|
||||
.orderBy(desc(importLogs.importedAt));
|
||||
.orderBy(desc(importLogs.importedAt))
|
||||
.limit(options.limit)
|
||||
.offset(options.offset);
|
||||
const [total] = await db.select({ total: count() }).from(importLogs).where(eq(importLogs.userId, userId));
|
||||
return { items, total: Number(total?.total ?? 0) };
|
||||
}
|
||||
|
||||
export async function getAllImportLogsWithDetails() {
|
||||
export async function getAllImportLogsWithDetails(options: ImportLogPageOptions) {
|
||||
const db = await getDb();
|
||||
if (!db) return [];
|
||||
return db.select({
|
||||
if (!db) return { items: [], total: 0 };
|
||||
const items = await db.select({
|
||||
...getTableColumns(importLogs),
|
||||
userName: users.name,
|
||||
userEmail: users.email,
|
||||
@@ -601,7 +610,11 @@ export async function getAllImportLogsWithDetails() {
|
||||
.from(importLogs)
|
||||
.leftJoin(users, eq(importLogs.userId, users.id))
|
||||
.leftJoin(sourceFiles, eq(importLogs.sourceFileId, sourceFiles.id))
|
||||
.orderBy(desc(importLogs.importedAt));
|
||||
.orderBy(desc(importLogs.importedAt))
|
||||
.limit(options.limit)
|
||||
.offset(options.offset);
|
||||
const [total] = await db.select({ total: count() }).from(importLogs);
|
||||
return { items, total: Number(total?.total ?? 0) };
|
||||
}
|
||||
|
||||
export async function deleteAllImportLogs(userId: number | null): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user