mirror of
https://github.com/documenso/documenso.git
synced 2025-11-16 09:41:35 +10:00
feat: add envelopes api
This commit is contained in:
@ -0,0 +1,41 @@
|
||||
import { createEnvelopeRecipients } from '@documenso/lib/server-only/recipient/create-envelope-recipients';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZCreateEnvelopeRecipientsRequestSchema,
|
||||
ZCreateEnvelopeRecipientsResponseSchema,
|
||||
} from './create-envelope-recipients.types';
|
||||
|
||||
export const createEnvelopeRecipientsRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/recipient/create-many',
|
||||
summary: 'Create envelope recipients',
|
||||
description: 'Create multiple recipients for an envelope',
|
||||
tags: ['Envelope Recipients'],
|
||||
},
|
||||
})
|
||||
.input(ZCreateEnvelopeRecipientsRequestSchema)
|
||||
.output(ZCreateEnvelopeRecipientsResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { user, teamId, metadata } = ctx;
|
||||
const { envelopeId, data: recipients } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeId,
|
||||
},
|
||||
});
|
||||
|
||||
return await createEnvelopeRecipients({
|
||||
userId: user.id,
|
||||
teamId,
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
id: envelopeId,
|
||||
},
|
||||
recipients,
|
||||
requestMetadata: metadata,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,21 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZEnvelopeRecipientLiteSchema } from '@documenso/lib/types/recipient';
|
||||
|
||||
import { ZCreateRecipientSchema } from '../../recipient-router/schema';
|
||||
|
||||
export const ZCreateEnvelopeRecipientsRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
data: ZCreateRecipientSchema.array(),
|
||||
});
|
||||
|
||||
export const ZCreateEnvelopeRecipientsResponseSchema = z.object({
|
||||
recipients: ZEnvelopeRecipientLiteSchema.array(),
|
||||
});
|
||||
|
||||
export type TCreateEnvelopeRecipientsRequest = z.infer<
|
||||
typeof ZCreateEnvelopeRecipientsRequestSchema
|
||||
>;
|
||||
export type TCreateEnvelopeRecipientsResponse = z.infer<
|
||||
typeof ZCreateEnvelopeRecipientsResponseSchema
|
||||
>;
|
||||
@ -0,0 +1,37 @@
|
||||
import { deleteEnvelopeRecipient } from '@documenso/lib/server-only/recipient/delete-envelope-recipient';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZDeleteEnvelopeRecipientRequestSchema,
|
||||
ZDeleteEnvelopeRecipientResponseSchema,
|
||||
} from './delete-envelope-recipient.types';
|
||||
|
||||
export const deleteEnvelopeRecipientRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/recipient/delete',
|
||||
summary: 'Delete envelope recipient',
|
||||
description: 'Delete an envelope recipient',
|
||||
tags: ['Envelope Recipient'],
|
||||
},
|
||||
})
|
||||
.input(ZDeleteEnvelopeRecipientRequestSchema)
|
||||
.output(ZDeleteEnvelopeRecipientResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { user, teamId, metadata } = ctx;
|
||||
const { recipientId } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
recipientId,
|
||||
},
|
||||
});
|
||||
|
||||
await deleteEnvelopeRecipient({
|
||||
userId: user.id,
|
||||
teamId,
|
||||
recipientId,
|
||||
requestMetadata: metadata,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ZDeleteEnvelopeRecipientRequestSchema = z.object({
|
||||
recipientId: z.number(),
|
||||
});
|
||||
|
||||
export const ZDeleteEnvelopeRecipientResponseSchema = z.void();
|
||||
|
||||
export type TDeleteEnvelopeRecipientRequest = z.infer<typeof ZDeleteEnvelopeRecipientRequestSchema>;
|
||||
export type TDeleteEnvelopeRecipientResponse = z.infer<
|
||||
typeof ZDeleteEnvelopeRecipientResponseSchema
|
||||
>;
|
||||
@ -0,0 +1,52 @@
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { buildTeamWhereQuery } from '@documenso/lib/utils/teams';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZGetEnvelopeRecipientRequestSchema,
|
||||
ZGetEnvelopeRecipientResponseSchema,
|
||||
} from './get-envelope-recipient.types';
|
||||
|
||||
export const getEnvelopeRecipientRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'GET',
|
||||
path: '/envelope/recipient/{recipientId}',
|
||||
summary: 'Get envelope recipient',
|
||||
description: 'Returns an envelope recipient given an ID',
|
||||
tags: ['Envelope Recipient'],
|
||||
},
|
||||
})
|
||||
.input(ZGetEnvelopeRecipientRequestSchema)
|
||||
.output(ZGetEnvelopeRecipientResponseSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { teamId, user } = ctx;
|
||||
const { recipientId } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
recipientId,
|
||||
},
|
||||
});
|
||||
|
||||
const recipient = await prisma.recipient.findFirst({
|
||||
where: {
|
||||
id: recipientId,
|
||||
envelope: {
|
||||
team: buildTeamWhereQuery({ teamId, userId: user.id }),
|
||||
},
|
||||
},
|
||||
include: {
|
||||
fields: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!recipient) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Recipient not found',
|
||||
});
|
||||
}
|
||||
|
||||
return recipient;
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZEnvelopeRecipientSchema } from '@documenso/lib/types/recipient';
|
||||
|
||||
export const ZGetEnvelopeRecipientRequestSchema = z.object({
|
||||
recipientId: z.number(),
|
||||
});
|
||||
|
||||
export const ZGetEnvelopeRecipientResponseSchema = ZEnvelopeRecipientSchema;
|
||||
|
||||
export type TGetEnvelopeRecipientRequest = z.infer<typeof ZGetEnvelopeRecipientRequestSchema>;
|
||||
export type TGetEnvelopeRecipientResponse = z.infer<typeof ZGetEnvelopeRecipientResponseSchema>;
|
||||
@ -0,0 +1,41 @@
|
||||
import { updateEnvelopeRecipients } from '@documenso/lib/server-only/recipient/update-envelope-recipients';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZUpdateEnvelopeRecipientsRequestSchema,
|
||||
ZUpdateEnvelopeRecipientsResponseSchema,
|
||||
} from './update-envelope-recipients.types';
|
||||
|
||||
export const updateEnvelopeRecipientsRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/recipient/update-many',
|
||||
summary: 'Update envelope recipients',
|
||||
description: 'Update multiple recipients for an envelope',
|
||||
tags: ['Envelope Recipient'],
|
||||
},
|
||||
})
|
||||
.input(ZUpdateEnvelopeRecipientsRequestSchema)
|
||||
.output(ZUpdateEnvelopeRecipientsResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { user, teamId } = ctx;
|
||||
const { envelopeId, data: recipients } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeId,
|
||||
},
|
||||
});
|
||||
|
||||
return await updateEnvelopeRecipients({
|
||||
userId: user.id,
|
||||
teamId,
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
id: envelopeId,
|
||||
},
|
||||
recipients,
|
||||
requestMetadata: ctx.metadata,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,21 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZRecipientLiteSchema } from '@documenso/lib/types/recipient';
|
||||
|
||||
import { ZUpdateRecipientSchema } from '../../recipient-router/schema';
|
||||
|
||||
export const ZUpdateEnvelopeRecipientsRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
data: ZUpdateRecipientSchema.array(),
|
||||
});
|
||||
|
||||
export const ZUpdateEnvelopeRecipientsResponseSchema = z.object({
|
||||
recipients: ZRecipientLiteSchema.array(),
|
||||
});
|
||||
|
||||
export type TUpdateEnvelopeRecipientsRequest = z.infer<
|
||||
typeof ZUpdateEnvelopeRecipientsRequestSchema
|
||||
>;
|
||||
export type TUpdateEnvelopeRecipientsResponse = z.infer<
|
||||
typeof ZUpdateEnvelopeRecipientsResponseSchema
|
||||
>;
|
||||
Reference in New Issue
Block a user