feat: add organisations (#1820)

This commit is contained in:
David Nguyen
2025-06-10 11:49:52 +10:00
committed by GitHub
parent 0b37f19641
commit e6dc237ad2
631 changed files with 37616 additions and 25695 deletions

View File

@ -3,24 +3,19 @@ import { deleteWebhookById } from '@documenso/lib/server-only/webhooks/delete-we
import { editWebhook } from '@documenso/lib/server-only/webhooks/edit-webhook';
import { getWebhookById } from '@documenso/lib/server-only/webhooks/get-webhook-by-id';
import { getWebhooksByTeamId } from '@documenso/lib/server-only/webhooks/get-webhooks-by-team-id';
import { getWebhooksByUserId } from '@documenso/lib/server-only/webhooks/get-webhooks-by-user-id';
import { authenticatedProcedure, router } from '../trpc';
import {
ZCreateWebhookMutationSchema,
ZDeleteWebhookMutationSchema,
ZEditWebhookMutationSchema,
ZGetTeamWebhooksQuerySchema,
ZGetWebhookByIdQuerySchema,
ZCreateWebhookRequestSchema,
ZDeleteWebhookRequestSchema,
ZEditWebhookRequestSchema,
ZGetTeamWebhooksRequestSchema,
ZGetWebhookByIdRequestSchema,
} from './schema';
export const webhookRouter = router({
getWebhooks: authenticatedProcedure.query(async ({ ctx }) => {
return await getWebhooksByUserId(ctx.user.id);
}),
getTeamWebhooks: authenticatedProcedure
.input(ZGetTeamWebhooksQuerySchema)
.input(ZGetTeamWebhooksRequestSchema)
.query(async ({ ctx, input }) => {
const { teamId } = input;
@ -28,7 +23,7 @@ export const webhookRouter = router({
}),
getWebhookById: authenticatedProcedure
.input(ZGetWebhookByIdQuerySchema)
.input(ZGetWebhookByIdRequestSchema)
.query(async ({ input, ctx }) => {
const { id, teamId } = input;
@ -40,7 +35,7 @@ export const webhookRouter = router({
}),
createWebhook: authenticatedProcedure
.input(ZCreateWebhookMutationSchema)
.input(ZCreateWebhookRequestSchema)
.mutation(async ({ input, ctx }) => {
const { enabled, eventTriggers, secret, webhookUrl, teamId } = input;
@ -55,7 +50,7 @@ export const webhookRouter = router({
}),
deleteWebhook: authenticatedProcedure
.input(ZDeleteWebhookMutationSchema)
.input(ZDeleteWebhookRequestSchema)
.mutation(async ({ input, ctx }) => {
const { id, teamId } = input;
@ -67,7 +62,7 @@ export const webhookRouter = router({
}),
editWebhook: authenticatedProcedure
.input(ZEditWebhookMutationSchema)
.input(ZEditWebhookRequestSchema)
.mutation(async ({ input, ctx }) => {
const { id, teamId, ...data } = input;

View File

@ -1,40 +1,40 @@
import { WebhookTriggerEvents } from '@prisma/client';
import { z } from 'zod';
export const ZGetTeamWebhooksQuerySchema = z.object({
export const ZGetTeamWebhooksRequestSchema = z.object({
teamId: z.number(),
});
export type TGetTeamWebhooksQuerySchema = z.infer<typeof ZGetTeamWebhooksQuerySchema>;
export type TGetTeamWebhooksRequestSchema = z.infer<typeof ZGetTeamWebhooksRequestSchema>;
export const ZCreateWebhookMutationSchema = z.object({
export const ZCreateWebhookRequestSchema = z.object({
webhookUrl: z.string().url(),
eventTriggers: z
.array(z.nativeEnum(WebhookTriggerEvents))
.min(1, { message: 'At least one event trigger is required' }),
secret: z.string().nullable(),
enabled: z.boolean(),
teamId: z.number().optional(),
teamId: z.number(),
});
export type TCreateWebhookFormSchema = z.infer<typeof ZCreateWebhookMutationSchema>;
export type TCreateWebhookFormSchema = z.infer<typeof ZCreateWebhookRequestSchema>;
export const ZGetWebhookByIdQuerySchema = z.object({
export const ZGetWebhookByIdRequestSchema = z.object({
id: z.string(),
teamId: z.number().optional(),
teamId: z.number(),
});
export type TGetWebhookByIdQuerySchema = z.infer<typeof ZGetWebhookByIdQuerySchema>;
export type TGetWebhookByIdRequestSchema = z.infer<typeof ZGetWebhookByIdRequestSchema>;
export const ZEditWebhookMutationSchema = ZCreateWebhookMutationSchema.extend({
export const ZEditWebhookRequestSchema = ZCreateWebhookRequestSchema.extend({
id: z.string(),
});
export type TEditWebhookMutationSchema = z.infer<typeof ZEditWebhookMutationSchema>;
export type TEditWebhookRequestSchema = z.infer<typeof ZEditWebhookRequestSchema>;
export const ZDeleteWebhookMutationSchema = z.object({
export const ZDeleteWebhookRequestSchema = z.object({
id: z.string(),
teamId: z.number().optional(),
teamId: z.number(),
});
export type TDeleteWebhookMutationSchema = z.infer<typeof ZDeleteWebhookMutationSchema>;
export type TDeleteWebhookRequestSchema = z.infer<typeof ZDeleteWebhookRequestSchema>;