diff --git a/packages/api/src/services/ProjectService.ts b/packages/api/src/services/ProjectService.ts index 6490031..df0e550 100644 --- a/packages/api/src/services/ProjectService.ts +++ b/packages/api/src/services/ProjectService.ts @@ -33,8 +33,8 @@ export class ProjectService { emails: { select: { createdAt: true } }, }, orderBy: [{ createdAt: "desc" }], - take: 20, - skip: (page - 1) * 20, + take: 100, + skip: (page - 1) * 100, }); }); }, @@ -145,41 +145,60 @@ export class ProjectService { const itemsPerPage = 10; const skip = (page - 1) * itemsPerPage; - const triggers = await prisma.trigger.findMany({ - where: { contact: { projectId: id } }, - include: { - contact: { - select: { - id: true, - email: true, + const [triggers, emails] = await Promise.all([ + prisma.trigger.findMany({ + where: { + contact: { + projectId: id + } + }, + select: { + id: true, + createdAt: true, + contact: { + select: { + id: true, + email: true, + }, + }, + event: { + select: { + name: true, + }, }, }, - event: { - select: { - name: true, + orderBy: {createdAt: 'desc'}, + take: itemsPerPage, + skip, + }), + prisma.email.findMany({ + where: { + contact: { + projectId: id + } + }, + select: { + id: true, + createdAt: true, + messageId: true, + status: true, + contact: { + select: { + id: true, + email: true, + }, }, }, - }, - orderBy: { createdAt: "desc" }, - }); - - const emails = await prisma.email.findMany({ - where: { contact: { projectId: id } }, - include: { - contact: { - select: { - id: true, - email: true, - }, - }, - }, - orderBy: { createdAt: "desc" }, - }); + orderBy: {createdAt: 'desc'}, + take: itemsPerPage, + skip, + }), + ]); const combined = [...triggers, ...emails]; combined.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime()); - return combined.slice(skip, skip + itemsPerPage); + return combined.slice(0, itemsPerPage); } public static usage(id: string) { diff --git a/packages/dashboard/src/pages/contacts/index.tsx b/packages/dashboard/src/pages/contacts/index.tsx index 0ce8aa7..d09dfe1 100644 --- a/packages/dashboard/src/pages/contacts/index.tsx +++ b/packages/dashboard/src/pages/contacts/index.tsx @@ -237,8 +237,8 @@ export default function Index() {