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,18 +1,20 @@
import { prisma } from '@documenso/prisma';
import type { Prisma } from '@documenso/prisma/client';
import type { FindResultResponse } from '../../types/search-params';
export interface FindDocumentsOptions {
term?: string;
query?: string;
page?: number;
perPage?: number;
}
export const findDocuments = async ({ term, page = 1, perPage = 10 }: FindDocumentsOptions) => {
const termFilters: Prisma.DocumentWhereInput | undefined = !term
export const findDocuments = async ({ query, page = 1, perPage = 10 }: FindDocumentsOptions) => {
const termFilters: Prisma.DocumentWhereInput | undefined = !query
? undefined
: {
title: {
contains: term,
contains: query,
mode: 'insensitive',
},
};
@ -51,5 +53,5 @@ export const findDocuments = async ({ term, page = 1, perPage = 10 }: FindDocume
currentPage: Math.max(page, 1),
perPage,
totalPages: Math.ceil(count / perPage),
};
} satisfies FindResultResponse<typeof data>;
};