File tree 1 file changed +20
-2
lines changed
src/backend/src/repository/typeorm/todo/queryService
1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { Connection , LessThanOrEqual , Repository } from 'typeorm' ;
2
2
import {
3
3
TodoQueryService ,
4
+ denyIfNotSet ,
5
+ AllTodosQuery ,
4
6
AllTodosWithDeadlineApproachingQuery ,
5
7
AllTodosWithDeadlineApproachingQueryResult ,
6
- AllTodosQuery ,
7
- denyIfNotSet ,
8
+ AllTodosByOwnerIdQuery ,
9
+ AllTodosByOwnerIdQueryResult ,
8
10
} from 'domain-model' ;
9
11
import addDays from 'date-fns/addDays' ;
10
12
@@ -48,4 +50,20 @@ export class GqlTodoQueryService implements TodoQueryService {
48
50
} ;
49
51
return res ;
50
52
}
53
+
54
+ public async allTodosByOwnerId ( query : AllTodosByOwnerIdQuery ) {
55
+ denyIfNotSet ( query , [ 'ownerId' ] ) ;
56
+ const { ownerId } = query ;
57
+
58
+ const result = await this . repository . find ( {
59
+ relations : [ 'owner' ] , // eager loading で resolver の負荷を下げる
60
+ where : { ownerId } ,
61
+ } ) ;
62
+ if ( ! result ) return { todos : null } ;
63
+
64
+ const res : AllTodosByOwnerIdQueryResult = {
65
+ todos : result . map ( ( todo ) => OrmTodoFactory . toDto ( todo ) ) ,
66
+ } ;
67
+ return res ;
68
+ }
51
69
}
You can’t perform that action at this time.
0 commit comments