mirror of
https://github.com/documenso/documenso.git
synced 2026-08-25 15:52:29 +10:00
feat: add recipient filter to documents search in admin panel
This commit is contained in:
@@ -2,6 +2,7 @@ import { prisma } from '@documenso/prisma';
|
||||
import { EnvelopeType, type Prisma } from '@prisma/client';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { MAX_POSTGRES_INT } from '../../constants/database';
|
||||
import type { FindResultResponse } from '../../types/search-params';
|
||||
|
||||
export interface AdminFindDocumentsOptions {
|
||||
@@ -10,7 +11,7 @@ export interface AdminFindDocumentsOptions {
|
||||
perPage?: number;
|
||||
}
|
||||
|
||||
const ZPositiveIntegerSchema = z.coerce.number().int().positive();
|
||||
const ZPositiveIntegerSchema = z.coerce.number().int().positive().max(MAX_POSTGRES_INT);
|
||||
|
||||
const emptyResponse = {
|
||||
data: [],
|
||||
@@ -58,6 +59,40 @@ export const adminFindDocuments = async ({ query, page = 1, perPage = 10 }: Admi
|
||||
}
|
||||
}
|
||||
|
||||
if (query?.startsWith('recipient:')) {
|
||||
const recipientQuery = query.slice('recipient:'.length).trim();
|
||||
|
||||
if (!recipientQuery) {
|
||||
return emptyResponse;
|
||||
}
|
||||
|
||||
// Match admin-global-search semantics: only bare digit strings are ID
|
||||
// lookups, so numeric-looking email fragments (1e3, 0x10, +40) stay text.
|
||||
const isRecipientIdLookup = /^\d+$/.test(recipientQuery);
|
||||
|
||||
const parsedRecipientId = ZPositiveIntegerSchema.safeParse(recipientQuery);
|
||||
|
||||
termFilters =
|
||||
isRecipientIdLookup && parsedRecipientId.success
|
||||
? {
|
||||
recipients: {
|
||||
some: {
|
||||
id: parsedRecipientId.data,
|
||||
},
|
||||
},
|
||||
}
|
||||
: {
|
||||
recipients: {
|
||||
some: {
|
||||
email: {
|
||||
contains: recipientQuery,
|
||||
mode: 'insensitive',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (query && query?.startsWith('envelope_')) {
|
||||
termFilters = {
|
||||
id: {
|
||||
|
||||
Reference in New Issue
Block a user