mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 09:12:02 +10:00
fix: refactor search routes (#1529)
Refactor find endpoints to be consistent in terms of input and output.
This commit is contained in:
@ -6,12 +6,13 @@ import type { TeamMember } from '@documenso/prisma/client';
|
||||
import { Prisma } from '@documenso/prisma/client';
|
||||
import { TeamMemberSchema, UserSchema } from '@documenso/prisma/generated/zod';
|
||||
|
||||
import { type FindResultSet, ZFindResultSet } from '../../types/find-result-set';
|
||||
import type { FindResultResponse } from '../../types/search-params';
|
||||
import { ZFindResultResponse } from '../../types/search-params';
|
||||
|
||||
export interface FindTeamMembersOptions {
|
||||
userId: number;
|
||||
teamId: number;
|
||||
term?: string;
|
||||
query?: string;
|
||||
page?: number;
|
||||
perPage?: number;
|
||||
orderBy?: {
|
||||
@ -20,7 +21,7 @@ export interface FindTeamMembersOptions {
|
||||
};
|
||||
}
|
||||
|
||||
export const ZFindTeamMembersResponseSchema = ZFindResultSet.extend({
|
||||
export const ZFindTeamMembersResponseSchema = ZFindResultResponse.extend({
|
||||
data: TeamMemberSchema.extend({
|
||||
user: UserSchema.pick({
|
||||
name: true,
|
||||
@ -34,7 +35,7 @@ export type TFindTeamMembersResponse = z.infer<typeof ZFindTeamMembersResponseSc
|
||||
export const findTeamMembers = async ({
|
||||
userId,
|
||||
teamId,
|
||||
term,
|
||||
query,
|
||||
page = 1,
|
||||
perPage = 10,
|
||||
orderBy,
|
||||
@ -54,11 +55,11 @@ export const findTeamMembers = async ({
|
||||
},
|
||||
});
|
||||
|
||||
const termFilters: Prisma.TeamMemberWhereInput | undefined = match(term)
|
||||
const termFilters: Prisma.TeamMemberWhereInput | undefined = match(query)
|
||||
.with(P.string.minLength(1), () => ({
|
||||
user: {
|
||||
name: {
|
||||
contains: term,
|
||||
contains: query,
|
||||
mode: Prisma.QueryMode.insensitive,
|
||||
},
|
||||
},
|
||||
@ -109,5 +110,5 @@ export const findTeamMembers = async ({
|
||||
currentPage: Math.max(page, 1),
|
||||
perPage,
|
||||
totalPages: Math.ceil(count / perPage),
|
||||
} satisfies FindResultSet<typeof data>;
|
||||
} satisfies FindResultResponse<typeof data>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user