Search TRPC Router (search/search.router.ts)

mperkins0155/crm · crm, CRM / Leads, backend, nestjs, trpc, search, router

Exposes a protected quick search endpoint via TRPC, delegating to SearchService.

// Source: https://github.com/mperkins0155/crm | License: MIT | Copyright 2026 Comp AI
// Provided via justclaw.it.com; keep this notice with the code.
import { Inject } from "@nestjs/common";
import { Input, Query, Router, UseMiddlewares } from "nestjs-trpc";
import { z } from "zod";
import { AuthMiddleware } from "../trpc/middlewares/auth.middleware";
import { SearchService } from "./search.service";

const quickInput = z.object({ q: z.string().default("") });

@Router({ alias: "search" })
@UseMiddlewares(AuthMiddleware)
export class SearchRouter {
	constructor(@Inject(SearchService) private readonly search: SearchService) {}

	@Query({ input: quickInput })
	async quick(@Input("q") q: string) {
		return this.search.quick(q);
	}
}

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key