Commit 895a794 1 parent d63703b commit 895a794 Copy full SHA for 895a794
File tree 1 file changed +10
-4
lines changed
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
1
2
import { Model } from 'mongoose' ;
2
3
import { IQuery } from '../interfaces/query.interface' ;
3
4
@@ -19,16 +20,19 @@ export abstract class BaseService<T> implements IBaseService<T> {
19
20
20
21
async findMany ( query : IQuery ) : Promise < IFindMany < T > > {
21
22
const [ total , docs ] = await Promise . all ( [
22
- this . model . countDocuments ( query . filter ) . limit ( query . limit ) ,
23
+ this . model . countDocuments ( query . filter ) ,
23
24
this . model
24
25
. find ( query . filter )
25
26
. limit ( query . limit )
26
27
. skip ( query . skip )
27
- . sort ( query . sort ) ,
28
+ . sort ( query . sort )
29
+ . exec ( ) ,
28
30
] ) ;
29
31
32
+ // @ts -ignore
33
+ const docsToJson = docs . map ( ( doc ) => doc ?. toJSON ( ) ) ;
30
34
return {
31
- docs,
35
+ docs : docsToJson ,
32
36
total,
33
37
limit : query . limit ,
34
38
page : query . skip / query . limit + 1 ,
@@ -37,6 +41,8 @@ export abstract class BaseService<T> implements IBaseService<T> {
37
41
}
38
42
39
43
async findOne ( id : number ) : Promise < T | null > {
40
- return this . model . findOne ( { id } ) . lean ( ) ;
44
+ const found = await this . model . findOne ( { id } ) ;
45
+ // @ts -ignore
46
+ return found . toJSON ( ) ;
41
47
}
42
48
}
You can’t perform that action at this time.
0 commit comments