Skip to content

Commit 2044e80

Browse files
committed
fix: better search
1 parent 61a0123 commit 2044e80

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

app/server/routers/book.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default {
2323
.object({
2424
cursor: z.string().cuid().optional(),
2525
limit: z.number().min(1).max(100).default(20),
26-
searchTerm: z.string().optional(),
26+
searchTerm: z.string().trim().optional().default(''),
2727
})
2828
.default({})
2929
)
@@ -38,10 +38,20 @@ export default {
3838
context.logger.info('Getting books from database');
3939

4040
const where = {
41-
title: {
42-
contains: input.searchTerm,
43-
mode: 'insensitive',
44-
},
41+
OR: [
42+
{
43+
title: {
44+
contains: input.searchTerm,
45+
mode: 'insensitive',
46+
},
47+
},
48+
{
49+
author: {
50+
contains: input.searchTerm,
51+
mode: 'insensitive',
52+
},
53+
},
54+
],
4555
} satisfies Prisma.BookWhereInput;
4656

4757
const [total, items] = await context.db.$transaction([

app/server/routers/user.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { auth } from '@/server/auth';
77
import { protectedProcedure } from '@/server/orpc';
88
import { getHeaders } from '@/server/utils';
99

10-
const tags = ['user'];
10+
const tags = ['users'];
1111

1212
export default {
1313
getAll: protectedProcedure({
@@ -25,7 +25,7 @@ export default {
2525
.object({
2626
cursor: z.string().optional(),
2727
limit: z.number().min(1).max(100).default(20),
28-
searchTerm: z.string().optional(),
28+
searchTerm: z.string().trim().optional().default(''),
2929
})
3030
.default({})
3131
)
@@ -38,10 +38,20 @@ export default {
3838
)
3939
.handler(async ({ context, input }) => {
4040
const where = {
41-
name: {
42-
contains: input.searchTerm,
43-
mode: 'insensitive',
44-
},
41+
OR: [
42+
{
43+
name: {
44+
contains: input.searchTerm,
45+
mode: 'insensitive',
46+
},
47+
},
48+
{
49+
email: {
50+
contains: input.searchTerm,
51+
mode: 'insensitive',
52+
},
53+
},
54+
],
4555
} satisfies Prisma.UserWhereInput;
4656

4757
context.logger.info('Getting users from database');

0 commit comments

Comments
 (0)