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,11 +1,12 @@
import type { FindResultSet } from '@documenso/lib/types/find-result-set';
import { prisma } from '@documenso/prisma';
import type { Team } from '@documenso/prisma/client';
import { Prisma } from '@documenso/prisma/client';
import type { FindResultResponse } from '../../types/search-params';
export interface FindTeamsOptions {
userId: number;
term?: string;
query?: string;
page?: number;
perPage?: number;
orderBy?: {
@@ -16,7 +17,7 @@ export interface FindTeamsOptions {
export const findTeams = async ({
userId,
term,
query,
page = 1,
perPage = 10,
orderBy,
@@ -32,9 +33,9 @@ export const findTeams = async ({
},
};
if (term && term.length > 0) {
if (query && query.length > 0) {
whereClause.name = {
contains: term,
contains: query,
mode: Prisma.QueryMode.insensitive,
};
}
@@ -72,5 +73,5 @@ export const findTeams = async ({
currentPage: Math.max(page, 1),
perPage,
totalPages: Math.ceil(count / perPage),
} satisfies FindResultSet<typeof maskedData>;
} satisfies FindResultResponse<typeof maskedData>;
};