Skip to content

Commit 064a45f

Browse files
committed
Add allTodosByOwnerId to repository
1 parent 62b2bb1 commit 064a45f

File tree

1 file changed

+20
-2
lines changed
  • src/backend/src/repository/typeorm/todo/queryService

1 file changed

+20
-2
lines changed

src/backend/src/repository/typeorm/todo/queryService/Todo.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Connection, LessThanOrEqual, Repository } from 'typeorm';
22
import {
33
TodoQueryService,
4+
denyIfNotSet,
5+
AllTodosQuery,
46
AllTodosWithDeadlineApproachingQuery,
57
AllTodosWithDeadlineApproachingQueryResult,
6-
AllTodosQuery,
7-
denyIfNotSet,
8+
AllTodosByOwnerIdQuery,
9+
AllTodosByOwnerIdQueryResult,
810
} from 'domain-model';
911
import addDays from 'date-fns/addDays';
1012

@@ -48,4 +50,20 @@ export class GqlTodoQueryService implements TodoQueryService {
4850
};
4951
return res;
5052
}
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+
}
5169
}

0 commit comments

Comments
 (0)