@@ -4,6 +4,7 @@ import { injectable, singleton } from 'tsyringe'
4
4
import { BuildQueryService } from './BuildQueryService.js'
5
5
import { PostIncludeTags } from '@services/PostService/PostServiceInterface.js'
6
6
import { Post } from '@prisma/client'
7
+ import { InternalServerError } from '@errors/InternalServerError.js'
7
8
8
9
interface Service {
9
10
get client ( ) : Client
@@ -138,26 +139,37 @@ export class ElasticSearchService implements Service {
138
139
139
140
query . script_score . query . bool . must . push ( privatePostsQuery )
140
141
141
- const result = await this . client . search ( {
142
- index : 'posts' ,
143
- body : {
144
- from,
145
- size,
146
- query,
147
- } ,
148
- } )
142
+ try {
143
+ const result = await this . client . search ( {
144
+ index : 'posts' ,
145
+ body : {
146
+ from,
147
+ size,
148
+ query,
149
+ } ,
150
+ } )
149
151
150
- const posts = result . body . hits . hits . map ( ( hit : any ) => hit . _source )
151
- posts . forEach ( ( p : any ) => {
152
- p . released_at = new Date ( p . released_at )
153
- } )
152
+ console . log ( 'result' , result )
154
153
155
- const data = {
156
- count : result . body . hits . total . value ,
157
- posts : result . body . hits . hits . map ( ( hit : any ) => hit . _source ) ,
158
- }
154
+ const posts = result . body . hits . hits . map ( ( hit : any ) => hit . _source )
155
+ posts . forEach ( ( p : any ) => {
156
+ p . released_at = new Date ( p . released_at )
157
+ } )
158
+
159
+ const data = {
160
+ count : result . body . hits . total . value ,
161
+ posts : result . body . hits . hits . map ( ( hit : any ) => hit . _source ) ,
162
+ }
159
163
160
- return data
164
+ // TODO: bug fix for elastic search
165
+ return {
166
+ count : 0 ,
167
+ posts : [ ] ,
168
+ }
169
+ } catch ( error ) {
170
+ console . log ( error )
171
+ throw new InternalServerError ( 'Internal Server Error' )
172
+ }
161
173
}
162
174
}
163
175
0 commit comments