mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 16:51:38 +10:00
fix: refactor search routes (#1529)
Refactor find endpoints to be consistent in terms of input and output.
This commit is contained in:
@ -74,20 +74,28 @@ import {
|
||||
} from './schema';
|
||||
|
||||
export const teamRouter = router({
|
||||
getTeams: authenticatedProcedure
|
||||
// Internal endpoint for now.
|
||||
getTeams: authenticatedProcedure.query(async ({ ctx }) => {
|
||||
return await getTeams({ userId: ctx.user.id });
|
||||
}),
|
||||
|
||||
findTeams: authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'GET',
|
||||
path: '/team',
|
||||
summary: 'Get teams',
|
||||
description: 'Returns all teams that you are a member of',
|
||||
summary: 'Find teams',
|
||||
description: 'Find your teams based on a search criteria',
|
||||
tags: ['Teams'],
|
||||
},
|
||||
})
|
||||
.input(z.void())
|
||||
.input(ZFindTeamsQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ ctx }) => {
|
||||
return await getTeams({ userId: ctx.user.id });
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeams({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
getTeam: authenticatedProcedure
|
||||
@ -327,14 +335,6 @@ export const teamRouter = router({
|
||||
});
|
||||
}),
|
||||
|
||||
// Todo: Refactor, seems to be a redundant endpoint.
|
||||
findTeams: authenticatedProcedure.input(ZFindTeamsQuerySchema).query(async ({ input, ctx }) => {
|
||||
return await findTeams({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
createTeamEmailVerification: authenticatedProcedure
|
||||
// .meta({
|
||||
|
||||
@ -2,17 +2,11 @@ import { z } from 'zod';
|
||||
|
||||
import { SUPPORTED_LANGUAGE_CODES } from '@documenso/lib/constants/i18n';
|
||||
import { PROTECTED_TEAM_URLS } from '@documenso/lib/constants/teams';
|
||||
import { ZFindSearchParamsSchema } from '@documenso/lib/types/search-params';
|
||||
import { DocumentVisibility, TeamMemberRole } from '@documenso/prisma/client';
|
||||
|
||||
import { ZUpdatePublicProfileMutationSchema } from '../profile-router/schema';
|
||||
|
||||
// Consider refactoring to use ZBaseTableSearchParamsSchema.
|
||||
const GenericFindQuerySchema = z.object({
|
||||
term: z.string().optional(),
|
||||
page: z.number().min(1).optional(),
|
||||
perPage: z.number().min(1).optional(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Restrict team URLs schema.
|
||||
*
|
||||
@ -122,17 +116,17 @@ export const ZFindTeamInvoicesQuerySchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZFindTeamMemberInvitesQuerySchema = GenericFindQuerySchema.extend({
|
||||
export const ZFindTeamMemberInvitesQuerySchema = ZFindSearchParamsSchema.extend({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZFindTeamMembersQuerySchema = GenericFindQuerySchema.extend({
|
||||
export const ZFindTeamMembersQuerySchema = ZFindSearchParamsSchema.extend({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZFindTeamsQuerySchema = GenericFindQuerySchema;
|
||||
export const ZFindTeamsQuerySchema = ZFindSearchParamsSchema;
|
||||
|
||||
export const ZFindTeamsPendingQuerySchema = GenericFindQuerySchema;
|
||||
export const ZFindTeamsPendingQuerySchema = ZFindSearchParamsSchema;
|
||||
|
||||
export const ZGetTeamQuerySchema = z.object({
|
||||
teamId: z.number(),
|
||||
|
||||
Reference in New Issue
Block a user