Showing
3 changed files
with
36 additions
and
0 deletions
... | @@ -85,4 +85,9 @@ export class PostController { | ... | @@ -85,4 +85,9 @@ export class PostController { |
85 | getComments(@Param('id') id) { | 85 | getComments(@Param('id') id) { |
86 | return this.postService.getComments(id); | 86 | return this.postService.getComments(id); |
87 | } | 87 | } |
88 | + | ||
89 | + @Post('search') | ||
90 | + search(@Body() body) { | ||
91 | + return this.postService.searchPost(body.search); | ||
92 | + } | ||
88 | } | 93 | } | ... | ... |
... | @@ -258,4 +258,34 @@ export class PostService { | ... | @@ -258,4 +258,34 @@ export class PostService { |
258 | }); | 258 | }); |
259 | return comments; | 259 | return comments; |
260 | } | 260 | } |
261 | + async searchPost(search: string) { | ||
262 | + const query: string = search.split(' ').join(' | '); | ||
263 | + const posts = await this.prisma.post.findMany({ | ||
264 | + where: { | ||
265 | + OR: [ | ||
266 | + { | ||
267 | + title: { | ||
268 | + search: query, | ||
269 | + }, | ||
270 | + }, | ||
271 | + { | ||
272 | + explain: { | ||
273 | + search: query, | ||
274 | + }, | ||
275 | + }, | ||
276 | + { | ||
277 | + example: { | ||
278 | + search: query, | ||
279 | + }, | ||
280 | + }, | ||
281 | + ], | ||
282 | + }, | ||
283 | + orderBy: { | ||
284 | + postlikes: { | ||
285 | + _count: 'desc', | ||
286 | + }, | ||
287 | + }, | ||
288 | + }); | ||
289 | + return posts; | ||
290 | + } | ||
261 | } | 291 | } | ... | ... |
-
Please register or login to post a comment