mirror of
https://github.com/documenso/documenso.git
synced 2025-11-22 04:31:39 +10:00
fix: refactor api routes
This commit is contained in:
@ -0,0 +1,18 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { acceptTeamInvitation } from '@documenso/lib/server-only/team/accept-team-invitation';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZAcceptTeamInvitationRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const acceptTeamInvitationRoute = authenticatedProcedure
|
||||
.input(ZAcceptTeamInvitationRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await acceptTeamInvitation({
|
||||
teamId: input.teamId,
|
||||
userId: ctx.user.id,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createTeamBillingPortal } from '@documenso/lib/server-only/team/create-team-billing-portal';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZCreateBillingPortalRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const createBillingPortalRoute = authenticatedProcedure
|
||||
.input(ZCreateBillingPortalRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeamBillingPortal({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,33 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createTeamEmailVerification } from '@documenso/lib/server-only/team/create-team-email-verification';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZCreateTeamEmailVerificationRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
name: z.string().trim().min(1, { message: 'Please enter a valid name.' }),
|
||||
email: z.string().trim().email().toLowerCase().min(1, 'Please enter a valid email.'),
|
||||
});
|
||||
|
||||
export const createTeamEmailVerificationRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/email/create',
|
||||
// summary: 'Create team email',
|
||||
// description: 'Add an email to a team and send an email request to verify it',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZCreateTeamEmailVerificationRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeamEmailVerification({
|
||||
teamId: input.teamId,
|
||||
userId: ctx.user.id,
|
||||
data: {
|
||||
email: input.email,
|
||||
name: input.name,
|
||||
},
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,36 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createTeamMemberInvites } from '@documenso/lib/server-only/team/create-team-member-invites';
|
||||
import { TeamMemberRole } from '@documenso/prisma/client';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZCreateTeamMemberInvitesRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
invitations: z.array(
|
||||
z.object({
|
||||
email: z.string().email().toLowerCase(),
|
||||
role: z.nativeEnum(TeamMemberRole),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
export const createTeamMemberInvitesRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/member/invite',
|
||||
// summary: 'Invite members',
|
||||
// description: 'Send email invitations to users to join the team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZCreateTeamMemberInvitesRequestSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeamMemberInvites({
|
||||
userId: ctx.user.id,
|
||||
userName: ctx.user.name ?? '',
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createTeamPendingCheckoutSession } from '@documenso/lib/server-only/team/create-team-checkout-session';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZCreateTeamPendingCheckoutRouteRequestSchema = z.object({
|
||||
interval: z.union([z.literal('monthly'), z.literal('yearly')]),
|
||||
pendingTeamId: z.number(),
|
||||
});
|
||||
|
||||
export const createTeamPendingCheckoutRoute = authenticatedProcedure
|
||||
.input(ZCreateTeamPendingCheckoutRouteRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeamPendingCheckoutSession({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
29
packages/trpc/server/team-router/create-team-route.ts
Normal file
29
packages/trpc/server/team-router/create-team-route.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createTeam } from '@documenso/lib/server-only/team/create-team';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import { ZTeamNameSchema, ZTeamUrlSchema } from './schema';
|
||||
|
||||
export const ZCreateTeamRequestSchema = z.object({
|
||||
teamName: ZTeamNameSchema,
|
||||
teamUrl: ZTeamUrlSchema,
|
||||
});
|
||||
|
||||
export const createTeamRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/create',
|
||||
// summary: 'Create team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZCreateTeamRequestSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeam({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { declineTeamInvitation } from '@documenso/lib/server-only/team/decline-team-invitation';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZDeclineTeamInvitationRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const declineTeamInvitationRoute = authenticatedProcedure
|
||||
.input(ZDeclineTeamInvitationRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await declineTeamInvitation({
|
||||
teamId: input.teamId,
|
||||
userId: ctx.user.id,
|
||||
});
|
||||
});
|
||||
28
packages/trpc/server/team-router/delete-team-email-route.ts
Normal file
28
packages/trpc/server/team-router/delete-team-email-route.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { deleteTeamEmail } from '@documenso/lib/server-only/team/delete-team-email';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZDeleteTeamEmailRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const deleteTeamEmailRequestRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/email/delete',
|
||||
// summary: 'Delete team email',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamEmailRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamEmail({
|
||||
userId: ctx.user.id,
|
||||
userEmail: ctx.user.email,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,26 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { deleteTeamEmailVerification } from '@documenso/lib/server-only/team/delete-team-email-verification';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZDeleteTeamEmailVerificationRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const deleteTeamEmailVerificationRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/email/verify/delete',
|
||||
// summary: 'Delete team email verification',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamEmailVerificationRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamEmailVerification({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,29 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { deleteTeamMemberInvitations } from '@documenso/lib/server-only/team/delete-team-invitations';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZDeleteTeamMemberInvitationsRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
invitationIds: z.array(z.number()),
|
||||
});
|
||||
|
||||
export const deleteTeamMemberInvitationRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/member/invite/delete',
|
||||
// summary: 'Delete member invite',
|
||||
// description: 'Delete a pending team member invite',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamMemberInvitationsRequestSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamMemberInvitations({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,29 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { deleteTeamMembers } from '@documenso/lib/server-only/team/delete-team-members';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZDeleteTeamMembersRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
teamMemberIds: z.array(z.number()),
|
||||
});
|
||||
|
||||
export const deleteTeamMembersRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/member/delete',
|
||||
// summary: 'Delete members',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamMembersRequestSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamMembers({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,27 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { deleteTeamPending } from '@documenso/lib/server-only/team/delete-team-pending';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZDeleteTeamPendingRequestSchema = z.object({
|
||||
pendingTeamId: z.number(),
|
||||
});
|
||||
|
||||
export const deleteTeamPendingRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/pending/{pendingTeamId}/delete',
|
||||
// summary: 'Delete pending team',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamPendingRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamPending({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
27
packages/trpc/server/team-router/delete-team-route.ts
Normal file
27
packages/trpc/server/team-router/delete-team-route.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { deleteTeam } from '@documenso/lib/server-only/team/delete-team';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZDeleteTeamRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const deleteTeamRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/delete',
|
||||
// summary: 'Delete team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamRequestSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeam({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,30 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { requestTeamOwnershipTransfer } from '@documenso/lib/server-only/team/request-team-ownership-transfer';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZDeleteTeamTransferRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
newOwnerUserId: z.number(),
|
||||
clearPaymentMethods: z.boolean(),
|
||||
});
|
||||
|
||||
export const deleteTeamTransferRequestRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/transfer',
|
||||
// summary: 'Request a team ownership transfer',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamTransferRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await requestTeamOwnershipTransfer({
|
||||
userId: ctx.user.id,
|
||||
userName: ctx.user.name ?? '',
|
||||
...input,
|
||||
});
|
||||
});
|
||||
18
packages/trpc/server/team-router/find-team-invoices-route.ts
Normal file
18
packages/trpc/server/team-router/find-team-invoices-route.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { findTeamInvoices } from '@documenso/lib/server-only/team/find-team-invoices';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZFindTeamInvoicesResponseSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const findTeamInvoicesRoute = authenticatedProcedure
|
||||
.input(ZFindTeamInvoicesResponseSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeamInvoices({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,29 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { findTeamMemberInvites } from '@documenso/lib/server-only/team/find-team-member-invites';
|
||||
import { ZFindSearchParamsSchema } from '@documenso/lib/types/search-params';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZFindTeamMemberInvitesRequestSchema = ZFindSearchParamsSchema.extend({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const findTeamMemberInvitesRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/{teamId}/member/invite',
|
||||
// summary: 'Find member invites',
|
||||
// description: 'Returns pending team member invites',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZFindTeamMemberInvitesRequestSchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeamMemberInvites({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
29
packages/trpc/server/team-router/find-team-members-route.ts
Normal file
29
packages/trpc/server/team-router/find-team-members-route.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { findTeamMembers } from '@documenso/lib/server-only/team/find-team-members';
|
||||
import { ZFindSearchParamsSchema } from '@documenso/lib/types/search-params';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZFindTeamMembersRequestSchema = ZFindSearchParamsSchema.extend({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const findTeamMembersRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/{teamId}/member/find',
|
||||
// summary: 'Find members',
|
||||
// description: 'Find team members based on a search criteria',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZFindTeamMembersRequestSchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeamMembers({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
24
packages/trpc/server/team-router/find-teams-pending-route.ts
Normal file
24
packages/trpc/server/team-router/find-teams-pending-route.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { findTeamsPending } from '@documenso/lib/server-only/team/find-teams-pending';
|
||||
import { ZFindSearchParamsSchema } from '@documenso/lib/types/search-params';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZFindTeamsPendingRequestSchema = ZFindSearchParamsSchema;
|
||||
|
||||
export const findTeamsPendingRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/pending',
|
||||
// summary: 'Find pending teams',
|
||||
// description: 'Find teams that are pending payment',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZFindTeamsPendingRequestSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeamsPending({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
27
packages/trpc/server/team-router/find-teams-route.ts
Normal file
27
packages/trpc/server/team-router/find-teams-route.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { findTeams } from '@documenso/lib/server-only/team/find-teams';
|
||||
import { ZFindSearchParamsSchema } from '@documenso/lib/types/search-params';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZFindTeamsRequestSchema = ZFindSearchParamsSchema;
|
||||
|
||||
export const findTeamsRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team',
|
||||
// summary: 'Find teams',
|
||||
// description: 'Find your teams based on a search criteria',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZFindTeamsRequestSchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeams({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,7 @@
|
||||
import { getTeamEmailByEmail } from '@documenso/lib/server-only/team/get-team-email-by-email';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const getTeamEmailByEmailRoute = authenticatedProcedure.query(async ({ ctx }) => {
|
||||
return await getTeamEmailByEmail({ email: ctx.user.email });
|
||||
});
|
||||
@ -0,0 +1,20 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getTeamInvitations } from '@documenso/lib/server-only/team/get-team-invitations';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const getTeamInvitationsRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/invite',
|
||||
// summary: 'Get team invitations',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(z.void())
|
||||
.query(async ({ ctx }) => {
|
||||
return await getTeamInvitations({ email: ctx.user.email });
|
||||
});
|
||||
24
packages/trpc/server/team-router/get-team-members-route.ts
Normal file
24
packages/trpc/server/team-router/get-team-members-route.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getTeamMembers } from '@documenso/lib/server-only/team/get-team-members';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZGetTeamMembersRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const getTeamMembersRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/{teamId}/member',
|
||||
// summary: 'Get members',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZGetTeamMembersRequestSchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await getTeamMembers({ teamId: input.teamId, userId: ctx.user.id });
|
||||
});
|
||||
@ -0,0 +1,7 @@
|
||||
import { getTeamPrices } from '@documenso/ee/server-only/stripe/get-team-prices';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const getTeamPricesRoute = authenticatedProcedure.query(async () => {
|
||||
return await getTeamPrices();
|
||||
});
|
||||
24
packages/trpc/server/team-router/get-team-route.ts
Normal file
24
packages/trpc/server/team-router/get-team-route.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getTeamById } from '@documenso/lib/server-only/team/get-team';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZGetTeamRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const getTeamRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/{teamId}',
|
||||
// summary: 'Get team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZGetTeamRequestSchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await getTeamById({ teamId: input.teamId, userId: ctx.user.id });
|
||||
});
|
||||
7
packages/trpc/server/team-router/get-teams-route.ts
Normal file
7
packages/trpc/server/team-router/get-teams-route.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { getTeams } from '@documenso/lib/server-only/team/get-teams';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const getTeamsRoute = authenticatedProcedure.query(async ({ ctx }) => {
|
||||
return await getTeams({ userId: ctx.user.id });
|
||||
});
|
||||
28
packages/trpc/server/team-router/leave-team-route.ts
Normal file
28
packages/trpc/server/team-router/leave-team-route.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { leaveTeam } from '@documenso/lib/server-only/team/leave-team';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZLeaveTeamRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const leaveTeamRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/leave',
|
||||
// summary: 'Leave a team',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZLeaveTeamRequestSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await leaveTeam({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,30 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { requestTeamOwnershipTransfer } from '@documenso/lib/server-only/team/request-team-ownership-transfer';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZRequestTeamOwnershipTransferRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
newOwnerUserId: z.number(),
|
||||
clearPaymentMethods: z.boolean(),
|
||||
});
|
||||
|
||||
export const requestTeamOwnershipTransferRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/transfer',
|
||||
// summary: 'Request a team ownership transfer',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZRequestTeamOwnershipTransferRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await requestTeamOwnershipTransfer({
|
||||
userId: ctx.user.id,
|
||||
userName: ctx.user.name ?? '',
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,26 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { resendTeamEmailVerification } from '@documenso/lib/server-only/team/resend-team-email-verification';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZResendTeamEmailVerificationRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const resendTeamEmailVerificationRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/email/resend',
|
||||
// summary: 'Resend team email verification',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZResendTeamEmailVerificationRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
await resendTeamEmailVerification({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,30 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { resendTeamMemberInvitation } from '@documenso/lib/server-only/team/resend-team-member-invitation';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZResendTeamMemberInvitationRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
invitationId: z.number(),
|
||||
});
|
||||
|
||||
export const resendTeamMemberInvitationRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/member/invite/{invitationId}/resend',
|
||||
// summary: 'Resend member invite',
|
||||
// description: 'Resend an email invitation to a user to join the team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZResendTeamMemberInvitationRequestSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
await resendTeamMemberInvitation({
|
||||
userId: ctx.user.id,
|
||||
userName: ctx.user.name ?? '',
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -1,669 +1,81 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getTeamPrices } from '@documenso/ee/server-only/stripe/get-team-prices';
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { acceptTeamInvitation } from '@documenso/lib/server-only/team/accept-team-invitation';
|
||||
import { createTeam } from '@documenso/lib/server-only/team/create-team';
|
||||
import { createTeamBillingPortal } from '@documenso/lib/server-only/team/create-team-billing-portal';
|
||||
import { createTeamPendingCheckoutSession } from '@documenso/lib/server-only/team/create-team-checkout-session';
|
||||
import { createTeamEmailVerification } from '@documenso/lib/server-only/team/create-team-email-verification';
|
||||
import { createTeamMemberInvites } from '@documenso/lib/server-only/team/create-team-member-invites';
|
||||
import { declineTeamInvitation } from '@documenso/lib/server-only/team/decline-team-invitation';
|
||||
import { deleteTeam } from '@documenso/lib/server-only/team/delete-team';
|
||||
import { deleteTeamEmail } from '@documenso/lib/server-only/team/delete-team-email';
|
||||
import { deleteTeamEmailVerification } from '@documenso/lib/server-only/team/delete-team-email-verification';
|
||||
import { deleteTeamMemberInvitations } from '@documenso/lib/server-only/team/delete-team-invitations';
|
||||
import { deleteTeamMembers } from '@documenso/lib/server-only/team/delete-team-members';
|
||||
import { deleteTeamPending } from '@documenso/lib/server-only/team/delete-team-pending';
|
||||
import { deleteTeamTransferRequest } from '@documenso/lib/server-only/team/delete-team-transfer-request';
|
||||
import { findTeamInvoices } from '@documenso/lib/server-only/team/find-team-invoices';
|
||||
import { findTeamMemberInvites } from '@documenso/lib/server-only/team/find-team-member-invites';
|
||||
import { findTeamMembers } from '@documenso/lib/server-only/team/find-team-members';
|
||||
import { findTeams } from '@documenso/lib/server-only/team/find-teams';
|
||||
import { findTeamsPending } from '@documenso/lib/server-only/team/find-teams-pending';
|
||||
import { getTeamById } from '@documenso/lib/server-only/team/get-team';
|
||||
import { getTeamEmailByEmail } from '@documenso/lib/server-only/team/get-team-email-by-email';
|
||||
import { getTeamInvitations } from '@documenso/lib/server-only/team/get-team-invitations';
|
||||
import { getTeamMembers } from '@documenso/lib/server-only/team/get-team-members';
|
||||
import { getTeams } from '@documenso/lib/server-only/team/get-teams';
|
||||
import { leaveTeam } from '@documenso/lib/server-only/team/leave-team';
|
||||
import { requestTeamOwnershipTransfer } from '@documenso/lib/server-only/team/request-team-ownership-transfer';
|
||||
import { resendTeamEmailVerification } from '@documenso/lib/server-only/team/resend-team-email-verification';
|
||||
import { resendTeamMemberInvitation } from '@documenso/lib/server-only/team/resend-team-member-invitation';
|
||||
import { updateTeam } from '@documenso/lib/server-only/team/update-team';
|
||||
import { updateTeamBrandingSettings } from '@documenso/lib/server-only/team/update-team-branding-settings';
|
||||
import { updateTeamDocumentSettings } from '@documenso/lib/server-only/team/update-team-document-settings';
|
||||
import { updateTeamEmail } from '@documenso/lib/server-only/team/update-team-email';
|
||||
import { updateTeamMember } from '@documenso/lib/server-only/team/update-team-member';
|
||||
import { updateTeamPublicProfile } from '@documenso/lib/server-only/team/update-team-public-profile';
|
||||
|
||||
import { authenticatedProcedure, router } from '../trpc';
|
||||
import {
|
||||
ZAcceptTeamInvitationMutationSchema,
|
||||
ZCreateTeamBillingPortalMutationSchema,
|
||||
ZCreateTeamEmailVerificationMutationSchema,
|
||||
ZCreateTeamMemberInvitesMutationSchema,
|
||||
ZCreateTeamMutationSchema,
|
||||
ZCreateTeamPendingCheckoutMutationSchema,
|
||||
ZDeclineTeamInvitationMutationSchema,
|
||||
ZDeleteTeamEmailMutationSchema,
|
||||
ZDeleteTeamEmailVerificationMutationSchema,
|
||||
ZDeleteTeamMemberInvitationsMutationSchema,
|
||||
ZDeleteTeamMembersMutationSchema,
|
||||
ZDeleteTeamMutationSchema,
|
||||
ZDeleteTeamPendingMutationSchema,
|
||||
ZDeleteTeamTransferRequestMutationSchema,
|
||||
ZFindTeamInvoicesQuerySchema,
|
||||
ZFindTeamMemberInvitesQuerySchema,
|
||||
ZFindTeamMembersQuerySchema,
|
||||
ZFindTeamsPendingQuerySchema,
|
||||
ZFindTeamsQuerySchema,
|
||||
ZGetTeamMembersQuerySchema,
|
||||
ZGetTeamQuerySchema,
|
||||
ZLeaveTeamMutationSchema,
|
||||
ZRequestTeamOwnerhsipTransferMutationSchema,
|
||||
ZResendTeamEmailVerificationMutationSchema,
|
||||
ZResendTeamMemberInvitationMutationSchema,
|
||||
ZUpdateTeamBrandingSettingsMutationSchema,
|
||||
ZUpdateTeamDocumentSettingsMutationSchema,
|
||||
ZUpdateTeamEmailMutationSchema,
|
||||
ZUpdateTeamMemberMutationSchema,
|
||||
ZUpdateTeamMutationSchema,
|
||||
ZUpdateTeamPublicProfileMutationSchema,
|
||||
} from './schema';
|
||||
import { router } from '../trpc';
|
||||
import { acceptTeamInvitationRoute } from './accept-team-invitation-route';
|
||||
import { createBillingPortalRoute } from './create-billing-portal-route';
|
||||
import { createTeamEmailVerificationRoute } from './create-team-email-verification-route';
|
||||
import { createTeamMemberInvitesRoute } from './create-team-member-invites-route';
|
||||
import { createTeamPendingCheckoutRoute } from './create-team-pending-checkout-route';
|
||||
import { createTeamRoute } from './create-team-route';
|
||||
import { declineTeamInvitationRoute } from './decline-team-invitation-route';
|
||||
import { deleteTeamEmailRequestRoute } from './delete-team-email-route';
|
||||
import { deleteTeamEmailVerificationRoute } from './delete-team-email-verification-route';
|
||||
import { deleteTeamMemberInvitationRoute } from './delete-team-member-invitation-route';
|
||||
import { deleteTeamMembersRoute } from './delete-team-members-route';
|
||||
import { deleteTeamPendingRoute } from './delete-team-pending-route';
|
||||
import { deleteTeamRoute } from './delete-team-route';
|
||||
import { deleteTeamTransferRequestRoute } from './delete-team-transfer-request-route';
|
||||
import { findTeamInvoicesRoute } from './find-team-invoices-route';
|
||||
import { findTeamMemberInvitesRoute } from './find-team-member-invites-route';
|
||||
import { findTeamMembersRoute } from './find-team-members-route';
|
||||
import { findTeamsPendingRoute } from './find-teams-pending-route';
|
||||
import { findTeamsRoute } from './find-teams-route';
|
||||
import { getTeamEmailByEmailRoute } from './get-team-email-by-email-route';
|
||||
import { getTeamInvitationsRoute } from './get-team-invitations-route';
|
||||
import { getTeamMembersRoute } from './get-team-members-route';
|
||||
import { getTeamPricesRoute } from './get-team-prices-route';
|
||||
import { getTeamRoute } from './get-team-route';
|
||||
import { getTeamsRoute } from './get-teams-route';
|
||||
import { leaveTeamRoute } from './leave-team-route';
|
||||
import { requestTeamOwnershipTransferRoute } from './request-team-ownership-transfer-route';
|
||||
import { resendTeamEmailVerificationRoute } from './resend-team-email-verification-route';
|
||||
import { resendTeamMemberInvitationRoute } from './resend-team-member-invitation-route';
|
||||
import { updateTeamBrandingSettingsRoute } from './update-team-branding-settings-route';
|
||||
import { updateTeamDocumentSettingsRoute } from './update-team-document-settings-route';
|
||||
import { updateTeamEmailRequestRoute } from './update-team-email-route';
|
||||
import { updateTeamMemberRoute } from './update-team-member-route';
|
||||
import { updateTeamPublicProfileRoute } from './update-team-public-profile-route';
|
||||
import { updateTeamRoute } from './update-team-route';
|
||||
|
||||
export const teamRouter = router({
|
||||
// Internal endpoint for now.
|
||||
getTeams: authenticatedProcedure.query(async ({ ctx }) => {
|
||||
return await getTeams({ userId: ctx.user.id });
|
||||
}),
|
||||
findTeams: findTeamsRoute,
|
||||
getTeams: getTeamsRoute,
|
||||
getTeam: getTeamRoute,
|
||||
createTeam: createTeamRoute,
|
||||
updateTeam: updateTeamRoute,
|
||||
deleteTeam: deleteTeamRoute,
|
||||
leaveTeam: leaveTeamRoute,
|
||||
|
||||
// Todo: Public endpoint.
|
||||
findTeams: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team',
|
||||
// summary: 'Find teams',
|
||||
// description: 'Find your teams based on a search criteria',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZFindTeamsQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeams({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
findTeamMemberInvites: findTeamMemberInvitesRoute,
|
||||
getTeamInvitations: getTeamInvitationsRoute,
|
||||
createTeamMemberInvites: createTeamMemberInvitesRoute,
|
||||
resendTeamMemberInvitation: resendTeamMemberInvitationRoute,
|
||||
acceptTeamInvitation: acceptTeamInvitationRoute,
|
||||
declineTeamInvitation: declineTeamInvitationRoute,
|
||||
deleteTeamMemberInvitations: deleteTeamMemberInvitationRoute,
|
||||
|
||||
// Todo: Public endpoint.
|
||||
getTeam: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/{teamId}',
|
||||
// summary: 'Get team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZGetTeamQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await getTeamById({ teamId: input.teamId, userId: ctx.user.id });
|
||||
}),
|
||||
findTeamMembers: findTeamMembersRoute,
|
||||
getTeamMembers: getTeamMembersRoute,
|
||||
updateTeamMember: updateTeamMemberRoute,
|
||||
deleteTeamMembers: deleteTeamMembersRoute,
|
||||
|
||||
// Todo: Public endpoint.
|
||||
createTeam: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/create',
|
||||
// summary: 'Create team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZCreateTeamMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeam({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
createTeamEmailVerification: createTeamEmailVerificationRoute,
|
||||
updateTeamPublicProfile: updateTeamPublicProfileRoute,
|
||||
requestTeamOwnershipTransfer: requestTeamOwnershipTransferRoute,
|
||||
deleteTeamTransferRequest: deleteTeamTransferRequestRoute,
|
||||
getTeamEmailByEmail: getTeamEmailByEmailRoute,
|
||||
updateTeamEmail: updateTeamEmailRequestRoute,
|
||||
deleteTeamEmail: deleteTeamEmailRequestRoute,
|
||||
|
||||
// Todo: Public endpoint.
|
||||
updateTeam: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}',
|
||||
// summary: 'Update team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZUpdateTeamMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await updateTeam({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Todo: Public endpoint.
|
||||
deleteTeam: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/delete',
|
||||
// summary: 'Delete team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeam({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Todo: Public endpoint.
|
||||
leaveTeam: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/leave',
|
||||
// summary: 'Leave a team',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZLeaveTeamMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await leaveTeam({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Todo: Public endpoint.
|
||||
findTeamMemberInvites: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/{teamId}/member/invite',
|
||||
// summary: 'Find member invites',
|
||||
// description: 'Returns pending team member invites',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZFindTeamMemberInvitesQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeamMemberInvites({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Todo: Public endpoint.
|
||||
createTeamMemberInvites: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/member/invite',
|
||||
// summary: 'Invite members',
|
||||
// description: 'Send email invitations to users to join the team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZCreateTeamMemberInvitesMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeamMemberInvites({
|
||||
userId: ctx.user.id,
|
||||
userName: ctx.user.name ?? '',
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Todo: Public endpoint.
|
||||
resendTeamMemberInvitation: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/member/invite/{invitationId}/resend',
|
||||
// summary: 'Resend member invite',
|
||||
// description: 'Resend an email invitation to a user to join the team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZResendTeamMemberInvitationMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
await resendTeamMemberInvitation({
|
||||
userId: ctx.user.id,
|
||||
userName: ctx.user.name ?? '',
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Todo: Public endpoint.
|
||||
deleteTeamMemberInvitations: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/member/invite/delete',
|
||||
// summary: 'Delete member invite',
|
||||
// description: 'Delete a pending team member invite',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamMemberInvitationsMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamMemberInvitations({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Todo: Public endpoint.
|
||||
getTeamMembers: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/{teamId}/member',
|
||||
// summary: 'Get members',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZGetTeamMembersQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await getTeamMembers({ teamId: input.teamId, userId: ctx.user.id });
|
||||
}),
|
||||
|
||||
// Todo: Public endpoint.
|
||||
findTeamMembers: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/{teamId}/member/find',
|
||||
// summary: 'Find members',
|
||||
// description: 'Find team members based on a search criteria',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZFindTeamMembersQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeamMembers({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Todo: Public endpoint.
|
||||
updateTeamMember: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/member/{teamMemberId}',
|
||||
// summary: 'Update member',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZUpdateTeamMemberMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await updateTeamMember({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Todo: Public endpoint.
|
||||
deleteTeamMembers: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/member/delete',
|
||||
// summary: 'Delete members',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamMembersMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamMembers({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
createTeamEmailVerification: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/email/create',
|
||||
// summary: 'Create team email',
|
||||
// description: 'Add an email to a team and send an email request to verify it',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZCreateTeamEmailVerificationMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeamEmailVerification({
|
||||
teamId: input.teamId,
|
||||
userId: ctx.user.id,
|
||||
data: {
|
||||
email: input.email,
|
||||
name: input.name,
|
||||
},
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
getTeamInvitations: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/invite',
|
||||
// summary: 'Get team invitations',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(z.void())
|
||||
.query(async ({ ctx }) => {
|
||||
return await getTeamInvitations({ email: ctx.user.email });
|
||||
}),
|
||||
|
||||
// Todo: Public endpoint.
|
||||
updateTeamPublicProfile: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/profile',
|
||||
// summary: 'Update a team public profile',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZUpdateTeamPublicProfileMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
try {
|
||||
const { teamId, bio, enabled } = input;
|
||||
|
||||
await updateTeamPublicProfile({
|
||||
userId: ctx.user.id,
|
||||
teamId,
|
||||
data: {
|
||||
bio,
|
||||
enabled,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
const error = AppError.parseError(err);
|
||||
|
||||
if (error.code !== AppErrorCode.UNKNOWN_ERROR) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message:
|
||||
'We were unable to update your public profile. Please review the information you provided and try again.',
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
requestTeamOwnershipTransfer: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/transfer',
|
||||
// summary: 'Request a team ownership transfer',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZRequestTeamOwnerhsipTransferMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await requestTeamOwnershipTransfer({
|
||||
userId: ctx.user.id,
|
||||
userName: ctx.user.name ?? '',
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
deleteTeamTransferRequest: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/transfer/delete',
|
||||
// summary: 'Delete team transfer request',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamTransferRequestMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamTransferRequest({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Todo
|
||||
getTeamEmailByEmail: authenticatedProcedure.query(async ({ ctx }) => {
|
||||
return await getTeamEmailByEmail({ email: ctx.user.email });
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
updateTeamEmail: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/email',
|
||||
// summary: 'Update a team email',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZUpdateTeamEmailMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await updateTeamEmail({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
deleteTeamEmail: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/email/delete',
|
||||
// summary: 'Delete team email',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamEmailMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamEmail({
|
||||
userId: ctx.user.id,
|
||||
userEmail: ctx.user.email,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
resendTeamEmailVerification: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/email/resend',
|
||||
// summary: 'Resend team email verification',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZResendTeamEmailVerificationMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
await resendTeamEmailVerification({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
deleteTeamEmailVerification: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/email/verify/delete',
|
||||
// summary: 'Delete team email verification',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamEmailVerificationMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamEmailVerification({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
resendTeamEmailVerification: resendTeamEmailVerificationRoute,
|
||||
deleteTeamEmailVerification: deleteTeamEmailVerificationRoute,
|
||||
|
||||
// Internal endpoint. Use updateTeam instead.
|
||||
updateTeamBrandingSettings: authenticatedProcedure
|
||||
.input(ZUpdateTeamBrandingSettingsMutationSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { teamId, settings } = input;
|
||||
updateTeamBrandingSettings: updateTeamBrandingSettingsRoute,
|
||||
updateTeamDocumentSettings: updateTeamDocumentSettingsRoute,
|
||||
|
||||
return await updateTeamBrandingSettings({
|
||||
userId: ctx.user.id,
|
||||
teamId,
|
||||
settings,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
createTeamPendingCheckout: authenticatedProcedure
|
||||
.input(ZCreateTeamPendingCheckoutMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeamPendingCheckoutSession({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
findTeamInvoices: authenticatedProcedure
|
||||
.input(ZFindTeamInvoicesQuerySchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeamInvoices({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
getTeamPrices: authenticatedProcedure.query(async () => {
|
||||
return await getTeamPrices();
|
||||
}),
|
||||
|
||||
// Internal endpoint. Use updateTeam instead.
|
||||
updateTeamDocumentSettings: authenticatedProcedure
|
||||
.input(ZUpdateTeamDocumentSettingsMutationSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { teamId, settings } = input;
|
||||
|
||||
return await updateTeamDocumentSettings({
|
||||
userId: ctx.user.id,
|
||||
teamId,
|
||||
settings,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
acceptTeamInvitation: authenticatedProcedure
|
||||
.input(ZAcceptTeamInvitationMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await acceptTeamInvitation({
|
||||
teamId: input.teamId,
|
||||
userId: ctx.user.id,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
declineTeamInvitation: authenticatedProcedure
|
||||
.input(ZDeclineTeamInvitationMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await declineTeamInvitation({
|
||||
teamId: input.teamId,
|
||||
userId: ctx.user.id,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
createBillingPortal: authenticatedProcedure
|
||||
.input(ZCreateTeamBillingPortalMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeamBillingPortal({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
findTeamsPending: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/team/pending',
|
||||
// summary: 'Find pending teams',
|
||||
// description: 'Find teams that are pending payment',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZFindTeamsPendingQuerySchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeamsPending({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
deleteTeamPending: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/pending/{pendingTeamId}/delete',
|
||||
// summary: 'Delete pending team',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamPendingMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamPending({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
}),
|
||||
findTeamInvoices: findTeamInvoicesRoute,
|
||||
getTeamPrices: getTeamPricesRoute,
|
||||
createTeamPendingCheckout: createTeamPendingCheckoutRoute,
|
||||
createBillingPortal: createBillingPortalRoute,
|
||||
findTeamsPending: findTeamsPendingRoute,
|
||||
deleteTeamPending: deleteTeamPendingRoute,
|
||||
});
|
||||
|
||||
@ -1,11 +1,6 @@
|
||||
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';
|
||||
|
||||
/**
|
||||
* Restrict team URLs schema.
|
||||
@ -43,210 +38,3 @@ export const ZTeamNameSchema = z
|
||||
.trim()
|
||||
.min(3, { message: 'Team name must be at least 3 characters long.' })
|
||||
.max(30, { message: 'Team name must not exceed 30 characters.' });
|
||||
|
||||
export const ZAcceptTeamInvitationMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZDeclineTeamInvitationMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZCreateTeamBillingPortalMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZCreateTeamMutationSchema = z.object({
|
||||
teamName: ZTeamNameSchema,
|
||||
teamUrl: ZTeamUrlSchema,
|
||||
});
|
||||
|
||||
export const ZCreateTeamEmailVerificationMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
name: z.string().trim().min(1, { message: 'Please enter a valid name.' }),
|
||||
email: z.string().trim().email().toLowerCase().min(1, 'Please enter a valid email.'),
|
||||
});
|
||||
|
||||
export const ZCreateTeamMemberInvitesMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
invitations: z.array(
|
||||
z.object({
|
||||
email: z.string().email().toLowerCase(),
|
||||
role: z.nativeEnum(TeamMemberRole),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
export const ZCreateTeamPendingCheckoutMutationSchema = z.object({
|
||||
interval: z.union([z.literal('monthly'), z.literal('yearly')]),
|
||||
pendingTeamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZDeleteTeamEmailMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZDeleteTeamEmailVerificationMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZDeleteTeamMembersMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
teamMemberIds: z.array(z.number()),
|
||||
});
|
||||
|
||||
export const ZDeleteTeamMemberInvitationsMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
invitationIds: z.array(z.number()),
|
||||
});
|
||||
|
||||
export const ZDeleteTeamMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZDeleteTeamPendingMutationSchema = z.object({
|
||||
pendingTeamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZDeleteTeamTransferRequestMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZFindTeamInvoicesQuerySchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZFindTeamMemberInvitesQuerySchema = ZFindSearchParamsSchema.extend({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZFindTeamMembersQuerySchema = ZFindSearchParamsSchema.extend({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZFindTeamsQuerySchema = ZFindSearchParamsSchema;
|
||||
|
||||
export const ZFindTeamsPendingQuerySchema = ZFindSearchParamsSchema;
|
||||
|
||||
export const ZGetTeamQuerySchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZGetTeamMembersQuerySchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZLeaveTeamMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZUpdateTeamMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
data: z.object({
|
||||
name: ZTeamNameSchema,
|
||||
url: ZTeamUrlSchema,
|
||||
}),
|
||||
});
|
||||
|
||||
export const ZUpdateTeamEmailMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
data: z.object({
|
||||
name: z.string().trim().min(1),
|
||||
}),
|
||||
});
|
||||
|
||||
export const ZUpdateTeamMemberMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
teamMemberId: z.number(),
|
||||
data: z.object({
|
||||
role: z.nativeEnum(TeamMemberRole),
|
||||
}),
|
||||
});
|
||||
|
||||
export const ZUpdateTeamPublicProfileMutationSchema = ZUpdatePublicProfileMutationSchema.pick({
|
||||
bio: true,
|
||||
enabled: true,
|
||||
}).extend({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZRequestTeamOwnerhsipTransferMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
newOwnerUserId: z.number(),
|
||||
clearPaymentMethods: z.boolean(),
|
||||
});
|
||||
|
||||
export const ZResendTeamEmailVerificationMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const ZResendTeamMemberInvitationMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
invitationId: z.number(),
|
||||
});
|
||||
|
||||
export const ZUpdateTeamBrandingSettingsMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
settings: z.object({
|
||||
brandingEnabled: z.boolean().optional().default(false),
|
||||
brandingLogo: z.string().optional().default(''),
|
||||
brandingUrl: z.string().optional().default(''),
|
||||
brandingCompanyDetails: z.string().optional().default(''),
|
||||
}),
|
||||
});
|
||||
|
||||
export const ZUpdateTeamDocumentSettingsMutationSchema = z.object({
|
||||
teamId: z.number(),
|
||||
settings: z.object({
|
||||
documentVisibility: z
|
||||
.nativeEnum(DocumentVisibility)
|
||||
.optional()
|
||||
.default(DocumentVisibility.EVERYONE),
|
||||
documentLanguage: z.enum(SUPPORTED_LANGUAGE_CODES).optional().default('en'),
|
||||
includeSenderDetails: z.boolean().optional().default(false),
|
||||
typedSignatureEnabled: z.boolean().optional().default(true),
|
||||
includeSigningCertificate: z.boolean().optional().default(true),
|
||||
}),
|
||||
});
|
||||
|
||||
export type TCreateTeamMutationSchema = z.infer<typeof ZCreateTeamMutationSchema>;
|
||||
export type TCreateTeamEmailVerificationMutationSchema = z.infer<
|
||||
typeof ZCreateTeamEmailVerificationMutationSchema
|
||||
>;
|
||||
export type TCreateTeamMemberInvitesMutationSchema = z.infer<
|
||||
typeof ZCreateTeamMemberInvitesMutationSchema
|
||||
>;
|
||||
export type TCreateTeamPendingCheckoutMutationSchema = z.infer<
|
||||
typeof ZCreateTeamPendingCheckoutMutationSchema
|
||||
>;
|
||||
export type TDeleteTeamEmailMutationSchema = z.infer<typeof ZDeleteTeamEmailMutationSchema>;
|
||||
export type TDeleteTeamMembersMutationSchema = z.infer<typeof ZDeleteTeamMembersMutationSchema>;
|
||||
export type TDeleteTeamMutationSchema = z.infer<typeof ZDeleteTeamMutationSchema>;
|
||||
export type TDeleteTeamPendingMutationSchema = z.infer<typeof ZDeleteTeamPendingMutationSchema>;
|
||||
export type TDeleteTeamTransferRequestMutationSchema = z.infer<
|
||||
typeof ZDeleteTeamTransferRequestMutationSchema
|
||||
>;
|
||||
export type TFindTeamMemberInvitesQuerySchema = z.infer<typeof ZFindTeamMembersQuerySchema>;
|
||||
export type TFindTeamMembersQuerySchema = z.infer<typeof ZFindTeamMembersQuerySchema>;
|
||||
export type TFindTeamsQuerySchema = z.infer<typeof ZFindTeamsQuerySchema>;
|
||||
export type TFindTeamsPendingQuerySchema = z.infer<typeof ZFindTeamsPendingQuerySchema>;
|
||||
export type TGetTeamQuerySchema = z.infer<typeof ZGetTeamQuerySchema>;
|
||||
export type TGetTeamMembersQuerySchema = z.infer<typeof ZGetTeamMembersQuerySchema>;
|
||||
export type TLeaveTeamMutationSchema = z.infer<typeof ZLeaveTeamMutationSchema>;
|
||||
export type TUpdateTeamMutationSchema = z.infer<typeof ZUpdateTeamMutationSchema>;
|
||||
export type TUpdateTeamEmailMutationSchema = z.infer<typeof ZUpdateTeamEmailMutationSchema>;
|
||||
export type TRequestTeamOwnerhsipTransferMutationSchema = z.infer<
|
||||
typeof ZRequestTeamOwnerhsipTransferMutationSchema
|
||||
>;
|
||||
export type TResendTeamEmailVerificationMutationSchema = z.infer<
|
||||
typeof ZResendTeamEmailVerificationMutationSchema
|
||||
>;
|
||||
export type TResendTeamMemberInvitationMutationSchema = z.infer<
|
||||
typeof ZResendTeamMemberInvitationMutationSchema
|
||||
>;
|
||||
export type TUpdateTeamBrandingSettingsMutationSchema = z.infer<
|
||||
typeof ZUpdateTeamBrandingSettingsMutationSchema
|
||||
>;
|
||||
export type TUpdateTeamDocumentSettingsMutationSchema = z.infer<
|
||||
typeof ZUpdateTeamDocumentSettingsMutationSchema
|
||||
>;
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { updateTeamBrandingSettings } from '@documenso/lib/server-only/team/update-team-branding-settings';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZUpdateTeamBrandingSettingsRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
settings: z.object({
|
||||
brandingEnabled: z.boolean().optional().default(false),
|
||||
brandingLogo: z.string().optional().default(''),
|
||||
brandingUrl: z.string().optional().default(''),
|
||||
brandingCompanyDetails: z.string().optional().default(''),
|
||||
}),
|
||||
});
|
||||
|
||||
export const updateTeamBrandingSettingsRoute = authenticatedProcedure
|
||||
.input(ZUpdateTeamBrandingSettingsRequestSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { teamId, settings } = input;
|
||||
|
||||
return await updateTeamBrandingSettings({
|
||||
userId: ctx.user.id,
|
||||
teamId,
|
||||
settings,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,33 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { SUPPORTED_LANGUAGE_CODES } from '@documenso/lib/constants/i18n';
|
||||
import { updateTeamDocumentSettings } from '@documenso/lib/server-only/team/update-team-document-settings';
|
||||
import { DocumentVisibility } from '@documenso/prisma/client';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZUpdateTeamDocumentSettingsRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
settings: z.object({
|
||||
documentVisibility: z
|
||||
.nativeEnum(DocumentVisibility)
|
||||
.optional()
|
||||
.default(DocumentVisibility.EVERYONE),
|
||||
documentLanguage: z.enum(SUPPORTED_LANGUAGE_CODES).optional().default('en'),
|
||||
includeSenderDetails: z.boolean().optional().default(false),
|
||||
typedSignatureEnabled: z.boolean().optional().default(true),
|
||||
includeSigningCertificate: z.boolean().optional().default(true),
|
||||
}),
|
||||
});
|
||||
|
||||
export const updateTeamDocumentSettingsRoute = authenticatedProcedure
|
||||
.input(ZUpdateTeamDocumentSettingsRequestSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { teamId, settings } = input;
|
||||
|
||||
return await updateTeamDocumentSettings({
|
||||
userId: ctx.user.id,
|
||||
teamId,
|
||||
settings,
|
||||
});
|
||||
});
|
||||
30
packages/trpc/server/team-router/update-team-email-route.ts
Normal file
30
packages/trpc/server/team-router/update-team-email-route.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { updateTeamEmail } from '@documenso/lib/server-only/team/update-team-email';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZUpdateTeamEmailRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
data: z.object({
|
||||
name: z.string().trim().min(1),
|
||||
}),
|
||||
});
|
||||
|
||||
export const updateTeamEmailRequestRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/email',
|
||||
// summary: 'Update a team email',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZUpdateTeamEmailRequestSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await updateTeamEmail({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
32
packages/trpc/server/team-router/update-team-member-route.ts
Normal file
32
packages/trpc/server/team-router/update-team-member-route.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { updateTeamMember } from '@documenso/lib/server-only/team/update-team-member';
|
||||
import { TeamMemberRole } from '@documenso/prisma/client';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZUpdateTeamMemberRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
teamMemberId: z.number(),
|
||||
data: z.object({
|
||||
role: z.nativeEnum(TeamMemberRole),
|
||||
}),
|
||||
});
|
||||
|
||||
export const updateTeamMemberRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/member/{teamMemberId}',
|
||||
// summary: 'Update member',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZUpdateTeamMemberRequestSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await updateTeamMember({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,56 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { updateTeamPublicProfile } from '@documenso/lib/server-only/team/update-team-public-profile';
|
||||
|
||||
import { ZUpdatePublicProfileRequestSchema } from '../profile-router/update-public-profile-route';
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
|
||||
export const ZUpdateTeamPublicProfileRequestSchema = ZUpdatePublicProfileRequestSchema.pick({
|
||||
bio: true,
|
||||
enabled: true,
|
||||
}).extend({
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export const updateTeamPublicProfileRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}/profile',
|
||||
// summary: 'Update a team public profile',
|
||||
// description: '',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZUpdateTeamPublicProfileRequestSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
try {
|
||||
const { teamId, bio, enabled } = input;
|
||||
|
||||
await updateTeamPublicProfile({
|
||||
userId: ctx.user.id,
|
||||
teamId,
|
||||
data: {
|
||||
bio,
|
||||
enabled,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
const error = AppError.parseError(err);
|
||||
|
||||
if (error.code !== AppErrorCode.UNKNOWN_ERROR) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message:
|
||||
'We were unable to update your public profile. Please review the information you provided and try again.',
|
||||
});
|
||||
}
|
||||
});
|
||||
32
packages/trpc/server/team-router/update-team-route.ts
Normal file
32
packages/trpc/server/team-router/update-team-route.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { updateTeam } from '@documenso/lib/server-only/team/update-team';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import { ZTeamNameSchema, ZTeamUrlSchema } from './schema';
|
||||
|
||||
export const ZUpdateTeamRequestSchema = z.object({
|
||||
teamId: z.number(),
|
||||
data: z.object({
|
||||
name: ZTeamNameSchema,
|
||||
url: ZTeamUrlSchema,
|
||||
}),
|
||||
});
|
||||
|
||||
export const updateTeamRoute = authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/team/{teamId}',
|
||||
// summary: 'Update team',
|
||||
// tags: ['Teams'],
|
||||
// },
|
||||
// })
|
||||
.input(ZUpdateTeamRequestSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await updateTeam({
|
||||
userId: ctx.user.id,
|
||||
...input,
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user