mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
fix: update delete endpoint and add limits
This commit is contained in:
@ -193,6 +193,7 @@ export const DataTableActionDropdown = ({ row, team }: DataTableActionDropdownPr
|
|||||||
documentTitle={row.title}
|
documentTitle={row.title}
|
||||||
open={isDeleteDialogOpen}
|
open={isDeleteDialogOpen}
|
||||||
onOpenChange={setDeleteDialogOpen}
|
onOpenChange={setDeleteDialogOpen}
|
||||||
|
teamId={team?.id}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{isDuplicateDialogOpen && (
|
{isDuplicateDialogOpen && (
|
||||||
|
|||||||
@ -16,12 +16,13 @@ import {
|
|||||||
import { Input } from '@documenso/ui/primitives/input';
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
type DeleteDraftDocumentDialogProps = {
|
type DeleteDocumentDialogProps = {
|
||||||
id: number;
|
id: number;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onOpenChange: (_open: boolean) => void;
|
onOpenChange: (_open: boolean) => void;
|
||||||
status: DocumentStatus;
|
status: DocumentStatus;
|
||||||
documentTitle: string;
|
documentTitle: string;
|
||||||
|
teamId?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DeleteDocumentDialog = ({
|
export const DeleteDocumentDialog = ({
|
||||||
@ -30,7 +31,8 @@ export const DeleteDocumentDialog = ({
|
|||||||
onOpenChange,
|
onOpenChange,
|
||||||
status,
|
status,
|
||||||
documentTitle,
|
documentTitle,
|
||||||
}: DeleteDraftDocumentDialogProps) => {
|
teamId,
|
||||||
|
}: DeleteDocumentDialogProps) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
@ -61,7 +63,7 @@ export const DeleteDocumentDialog = ({
|
|||||||
|
|
||||||
const onDelete = async () => {
|
const onDelete = async () => {
|
||||||
try {
|
try {
|
||||||
await deleteDocument({ id });
|
await deleteDocument({ id, teamId });
|
||||||
} catch {
|
} catch {
|
||||||
toast({
|
toast({
|
||||||
title: 'Something went wrong',
|
title: 'Something went wrong',
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { createNextRoute } from '@ts-rest/next';
|
import { createNextRoute } from '@ts-rest/next';
|
||||||
|
|
||||||
|
import { getServerLimits } from '@documenso/ee/server-only/limits/server';
|
||||||
import { createDocumentData } from '@documenso/lib/server-only/document-data/create-document-data';
|
import { createDocumentData } from '@documenso/lib/server-only/document-data/create-document-data';
|
||||||
import { upsertDocumentMeta } from '@documenso/lib/server-only/document-meta/upsert-document-meta';
|
import { upsertDocumentMeta } from '@documenso/lib/server-only/document-meta/upsert-document-meta';
|
||||||
import { createDocument } from '@documenso/lib/server-only/document/create-document';
|
import { createDocument } from '@documenso/lib/server-only/document/create-document';
|
||||||
@ -131,6 +132,17 @@ export const ApiContractV1Implementation = createNextRoute(ApiContractV1, {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { remaining } = await getServerLimits({ email: user.email, teamId: team?.id });
|
||||||
|
|
||||||
|
if (remaining.documents <= 0) {
|
||||||
|
return {
|
||||||
|
status: 400,
|
||||||
|
body: {
|
||||||
|
message: 'You have reached the maximum number of documents allowed for this month',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const fileName = body.title.endsWith('.pdf') ? body.title : `${body.title}.pdf`;
|
const fileName = body.title.endsWith('.pdf') ? body.title : `${body.title}.pdf`;
|
||||||
|
|
||||||
const { url, key } = await getPresignPostUrl(fileName, 'application/pdf');
|
const { url, key } = await getPresignPostUrl(fileName, 'application/pdf');
|
||||||
@ -183,6 +195,17 @@ export const ApiContractV1Implementation = createNextRoute(ApiContractV1, {
|
|||||||
createDocumentFromTemplate: authenticatedMiddleware(async (args, user, team) => {
|
createDocumentFromTemplate: authenticatedMiddleware(async (args, user, team) => {
|
||||||
const { body, params } = args;
|
const { body, params } = args;
|
||||||
|
|
||||||
|
const { remaining } = await getServerLimits({ email: user.email, teamId: team?.id });
|
||||||
|
|
||||||
|
if (remaining.documents <= 0) {
|
||||||
|
return {
|
||||||
|
status: 400,
|
||||||
|
body: {
|
||||||
|
message: 'You have reached the maximum number of documents allowed for this month',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const templateId = Number(params.templateId);
|
const templateId = Number(params.templateId);
|
||||||
|
|
||||||
const fileName = body.title.endsWith('.pdf') ? body.title : `${body.title}.pdf`;
|
const fileName = body.title.endsWith('.pdf') ? body.title : `${body.title}.pdf`;
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import { extractNextApiRequestMetadata } from '@documenso/lib/universal/extract-
|
|||||||
import { authenticatedProcedure, procedure, router } from '../trpc';
|
import { authenticatedProcedure, procedure, router } from '../trpc';
|
||||||
import {
|
import {
|
||||||
ZCreateDocumentMutationSchema,
|
ZCreateDocumentMutationSchema,
|
||||||
ZDeleteDraftDocumentMutationSchema,
|
ZDeleteDraftDocumentMutationSchema as ZDeleteDocumentMutationSchema,
|
||||||
ZFindDocumentAuditLogsQuerySchema,
|
ZFindDocumentAuditLogsQuerySchema,
|
||||||
ZGetDocumentByIdQuerySchema,
|
ZGetDocumentByIdQuerySchema,
|
||||||
ZGetDocumentByTokenQuerySchema,
|
ZGetDocumentByTokenQuerySchema,
|
||||||
@ -106,17 +106,17 @@ export const documentRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
deleteDocument: authenticatedProcedure
|
deleteDocument: authenticatedProcedure
|
||||||
.input(ZDeleteDraftDocumentMutationSchema)
|
.input(ZDeleteDocumentMutationSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
const { id } = input;
|
const { id, teamId } = input;
|
||||||
|
|
||||||
const userId = ctx.user.id;
|
const userId = ctx.user.id;
|
||||||
|
|
||||||
return await deleteDocument({
|
return await deleteDocument({
|
||||||
id,
|
id,
|
||||||
userId,
|
userId,
|
||||||
// TODO: Get teamId
|
teamId,
|
||||||
requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { z } from 'zod';
|
|||||||
|
|
||||||
import { URL_REGEX } from '@documenso/lib/constants/url-regex';
|
import { URL_REGEX } from '@documenso/lib/constants/url-regex';
|
||||||
import { ZBaseTableSearchParamsSchema } from '@documenso/lib/types/search-params';
|
import { ZBaseTableSearchParamsSchema } from '@documenso/lib/types/search-params';
|
||||||
import { DocumentStatus, FieldType, RecipientRole } from '@documenso/prisma/client';
|
import { FieldType, RecipientRole } from '@documenso/prisma/client';
|
||||||
|
|
||||||
export const ZFindDocumentAuditLogsQuerySchema = ZBaseTableSearchParamsSchema.extend({
|
export const ZFindDocumentAuditLogsQuerySchema = ZBaseTableSearchParamsSchema.extend({
|
||||||
documentId: z.number().min(1),
|
documentId: z.number().min(1),
|
||||||
@ -115,6 +115,7 @@ export type TSendDocumentMutationSchema = z.infer<typeof ZSendDocumentMutationSc
|
|||||||
|
|
||||||
export const ZDeleteDraftDocumentMutationSchema = z.object({
|
export const ZDeleteDraftDocumentMutationSchema = z.object({
|
||||||
id: z.number().min(1),
|
id: z.number().min(1),
|
||||||
|
teamId: z.number().min(1).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TDeleteDraftDocumentMutationSchema = z.infer<typeof ZDeleteDraftDocumentMutationSchema>;
|
export type TDeleteDraftDocumentMutationSchema = z.infer<typeof ZDeleteDraftDocumentMutationSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user