fix: refactor search routes (#1529)

Refactor find endpoints to be consistent in terms of input and output.
This commit is contained in:
David Nguyen
2024-12-11 19:39:50 +09:00
committed by GitHub
parent 3d7b28a92b
commit 5df1a6602e
35 changed files with 171 additions and 184 deletions

View File

@ -1,6 +1,8 @@
import { prisma } from '@documenso/prisma';
import type { Prisma, Template } from '@documenso/prisma/client';
import type { FindResultResponse } from '../../types/search-params';
export type FindTemplatesOptions = {
userId: number;
teamId?: number;
@ -10,7 +12,7 @@ export type FindTemplatesOptions = {
};
export type FindTemplatesResponse = Awaited<ReturnType<typeof findTemplates>>;
export type FindTemplateRow = FindTemplatesResponse['templates'][number];
export type FindTemplateRow = FindTemplatesResponse['data'][number];
export const findTemplates = async ({
userId,
@ -38,7 +40,7 @@ export const findTemplates = async ({
};
}
const [templates, count] = await Promise.all([
const [data, count] = await Promise.all([
prisma.template.findMany({
where: whereFilter,
include: {
@ -75,7 +77,10 @@ export const findTemplates = async ({
]);
return {
templates,
data,
count,
currentPage: Math.max(page, 1),
perPage,
totalPages: Math.ceil(count / perPage),
};
} satisfies FindResultResponse<typeof data>;
};