mirror of
https://github.com/documenso/documenso.git
synced 2026-07-26 18:04:55 +10:00
feat: implement template search functionality (#2376)
- Added function to handle template searches based on user input - Introduced in the TRPC router to facilitate authenticated template searches - Updated to include template search results alongside document search results - Enhanced query handling by enabling searches only when the input is valid - Created corresponding Zod schemas for request and response validation in
This commit is contained in:
@@ -55,6 +55,7 @@ import {
|
||||
ZUpdateTemplateRequestSchema,
|
||||
ZUpdateTemplateResponseSchema,
|
||||
} from './schema';
|
||||
import { searchTemplateRoute } from './search-template';
|
||||
|
||||
export const templateRouter = router({
|
||||
/**
|
||||
@@ -160,6 +161,8 @@ export const templateRouter = router({
|
||||
*/
|
||||
getMany: getTemplatesByIdsRoute,
|
||||
|
||||
search: searchTemplateRoute,
|
||||
|
||||
/**
|
||||
* Wait until RR7 so we can passthrough documents.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { searchTemplatesWithKeyword } from '@documenso/lib/server-only/template/search-templates-with-keyword';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import {
|
||||
ZSearchTemplateRequestSchema,
|
||||
ZSearchTemplateResponseSchema,
|
||||
} from './search-template.types';
|
||||
|
||||
export const searchTemplateRoute = authenticatedProcedure
|
||||
.input(ZSearchTemplateRequestSchema)
|
||||
.output(ZSearchTemplateResponseSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { query } = input;
|
||||
|
||||
const templates = await searchTemplatesWithKeyword({
|
||||
query,
|
||||
userId: ctx.user.id,
|
||||
});
|
||||
|
||||
return templates;
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ZSearchTemplateRequestSchema = z.object({
|
||||
query: z.string().trim().min(1).max(1024),
|
||||
});
|
||||
|
||||
export const ZSearchTemplateResponseSchema = z
|
||||
.object({
|
||||
title: z.string(),
|
||||
path: z.string(),
|
||||
value: z.string(),
|
||||
})
|
||||
.array();
|
||||
|
||||
export type TSearchTemplateRequest = z.infer<typeof ZSearchTemplateRequestSchema>;
|
||||
export type TSearchTemplateResponse = z.infer<typeof ZSearchTemplateResponseSchema>;
|
||||
Reference in New Issue
Block a user