{"action":"created","comment":{"url":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/comments/214874752","pull_request_review_id":152016474,"id":214874752,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNDg3NDc1Mg==","diff_hunk":"@@ -0,0 +1,120 @@\n+import { INTERNAL_SERVER_ERROR, OK } from 'http-status-codes';\n+import * as Router from 'koa-router';\n+import {\n+    IApiResponse,\n+    AssignmentModel,\n+    IAssignmentModel,\n+    IUserSession,\n+    IEventModel,\n+    TaskModel,\n+    AssignmentStatus,\n+} from '../../models';\n+\n+type AssignmentResponse = {\n+    _id: string;\n+    assignmentRepo?: string;\n+    author?: string;\n+    checkDate?: number;\n+    completeDate?: number;\n+    courseId: string;\n+    deadlineDate: number;\n+    endDateTime?: number;\n+    mentorComment?: string;\n+    mentorId?: string;\n+    score: number;\n+    startDateTime: number;\n+    status: string;\n+    studentComment?: string;\n+    studentId: string;\n+    taskId: string;\n+    taskType?: string;\n+    title: string;\n+    type: string;\n+    urlToDescription?: string;\n+    whoChecks?: string;\n+};\n+\n+type INormalizeAssignments = {\n+    isEndAssignment: boolean;\n+    isActiveAssignment: boolean;\n+    assignment: AssignmentResponse;\n+};\n+\n+type NormalizeAssignmentsData = {\n+    assignments: INormalizeAssignments[];\n+};\n+\n+export const courseAssignmentsRoute = async (ctx: Router.IRouterContext) => {\n+    try {\n+        const userSession: IUserSession = ctx.state.user!;\n+        const { id: courseId } = ctx.params;\n+        const studentId: string = userSession._id;\n+        const assignments: IAssignmentModel[] = await getAssignmentsByCourseIdAndUserId(courseId, studentId);\n+        const arrayOfTasksId: string[] = [];\n+        for (const index in assignments) {\n+            if (assignments[index]) {\n+                arrayOfTasksId.push(assignments[index].taskId);\n+            }\n+        }\n+        const tasks: IEventModel[] = await getTasksByTaskId(arrayOfTasksId);\n+        const combinedAssignmentsAndTasks: AssignmentResponse[] = [];\n+        for (const index in assignments) {\n+            if (assignments[index] && tasks[index]) {\n+                combinedAssignmentsAndTasks[index] = { ...Object.create(null), ...tasks[index], ...assignments[index] };\n+            }","path":"app/routes/course/assignments.ts","position":60,"original_position":64,"commit_id":"a31a6e80a0d07a5dc5f45e70bed764b5ef2b5c3c","original_commit_id":"88a8acdcc2285944777115d46567e2e88513c33f","user":{"login":"KurnosovNikita","id":22590795,"node_id":"MDQ6VXNlcjIyNTkwNzk1","avatar_url":"https://avatars3.githubusercontent.com/u/22590795?v=4","gravatar_id":"","url":"https://api.github.com/users/KurnosovNikita","html_url":"https://github.com/KurnosovNikita","followers_url":"https://api.github.com/users/KurnosovNikita/followers","following_url":"https://api.github.com/users/KurnosovNikita/following{/other_user}","gists_url":"https://api.github.com/users/KurnosovNikita/gists{/gist_id}","starred_url":"https://api.github.com/users/KurnosovNikita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KurnosovNikita/subscriptions","organizations_url":"https://api.github.com/users/KurnosovNikita/orgs","repos_url":"https://api.github.com/users/KurnosovNikita/repos","events_url":"https://api.github.com/users/KurnosovNikita/events{/privacy}","received_events_url":"https://api.github.com/users/KurnosovNikita/received_events","type":"User","site_admin":false},"body":"It is impossible to implement this part with *aggregation*,  because we have to compare taskId(String) and _id(ObjectId) and there is no way to convert them to the same type(an example is given below). Tried with : _id.str , { \"$toString\": \"$_id\" }, $convert. We can try to change the type of \"taskId\" in the Assignment collection to ObjectId, but I don't think it would be a good idea.\r\n```javascript\r\nconst assignments = await AssignmentModel.aggregate([\r\n{\r\n$match: {courseId,studentId}\r\n},\r\n{\r\n$lookup:{\r\nfrom: 'tasks',\r\nlocalField: 'taskId', // String\r\nforeignField: '_id', // ObjectId\r\nas 'task'\r\n}\r\n},\r\n{\r\n$unwind: '$task'\r\n},\r\n])\r\n```\r\nPerhaps this can be done with *populate*, but so far I have not found a way to implement it.","created_at":"2018-09-04T11:09:27Z","updated_at":"2018-09-04T11:09:27Z","html_url":"https://github.com/rolling-scopes/rsschool-api/pull/17#discussion_r214874752","pull_request_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/17","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/comments/214874752"},"html":{"href":"https://github.com/rolling-scopes/rsschool-api/pull/17#discussion_r214874752"},"pull_request":{"href":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/17"}},"in_reply_to_id":214540809},"pull_request":{"url":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/17","id":212478765,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEyNDc4NzY1","html_url":"https://github.com/rolling-scopes/rsschool-api/pull/17","diff_url":"https://github.com/rolling-scopes/rsschool-api/pull/17.diff","patch_url":"https://github.com/rolling-scopes/rsschool-api/pull/17.patch","issue_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/issues/17","number":17,"state":"open","locked":false,"title":"Student Tasks Stage1(Assignments)","user":{"login":"KurnosovNikita","id":22590795,"node_id":"MDQ6VXNlcjIyNTkwNzk1","avatar_url":"https://avatars3.githubusercontent.com/u/22590795?v=4","gravatar_id":"","url":"https://api.github.com/users/KurnosovNikita","html_url":"https://github.com/KurnosovNikita","followers_url":"https://api.github.com/users/KurnosovNikita/followers","following_url":"https://api.github.com/users/KurnosovNikita/following{/other_user}","gists_url":"https://api.github.com/users/KurnosovNikita/gists{/gist_id}","starred_url":"https://api.github.com/users/KurnosovNikita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KurnosovNikita/subscriptions","organizations_url":"https://api.github.com/users/KurnosovNikita/orgs","repos_url":"https://api.github.com/users/KurnosovNikita/repos","events_url":"https://api.github.com/users/KurnosovNikita/events{/privacy}","received_events_url":"https://api.github.com/users/KurnosovNikita/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-08-31T19:47:09Z","updated_at":"2018-09-04T11:09:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"af5160afceb4ccbfd2addc1a3b3e9cfa4f0134c9","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/17/commits","review_comments_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/17/comments","review_comment_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/issues/17/comments","statuses_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/statuses/a31a6e80a0d07a5dc5f45e70bed764b5ef2b5c3c","head":{"label":"KurnosovNikita:Assignments","ref":"Assignments","sha":"a31a6e80a0d07a5dc5f45e70bed764b5ef2b5c3c","user":{"login":"KurnosovNikita","id":22590795,"node_id":"MDQ6VXNlcjIyNTkwNzk1","avatar_url":"https://avatars3.githubusercontent.com/u/22590795?v=4","gravatar_id":"","url":"https://api.github.com/users/KurnosovNikita","html_url":"https://github.com/KurnosovNikita","followers_url":"https://api.github.com/users/KurnosovNikita/followers","following_url":"https://api.github.com/users/KurnosovNikita/following{/other_user}","gists_url":"https://api.github.com/users/KurnosovNikita/gists{/gist_id}","starred_url":"https://api.github.com/users/KurnosovNikita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KurnosovNikita/subscriptions","organizations_url":"https://api.github.com/users/KurnosovNikita/orgs","repos_url":"https://api.github.com/users/KurnosovNikita/repos","events_url":"https://api.github.com/users/KurnosovNikita/events{/privacy}","received_events_url":"https://api.github.com/users/KurnosovNikita/received_events","type":"User","site_admin":false},"repo":{"id":143754173,"node_id":"MDEwOlJlcG9zaXRvcnkxNDM3NTQxNzM=","name":"rsschool-api","full_name":"KurnosovNikita/rsschool-api","owner":{"login":"KurnosovNikita","id":22590795,"node_id":"MDQ6VXNlcjIyNTkwNzk1","avatar_url":"https://avatars3.githubusercontent.com/u/22590795?v=4","gravatar_id":"","url":"https://api.github.com/users/KurnosovNikita","html_url":"https://github.com/KurnosovNikita","followers_url":"https://api.github.com/users/KurnosovNikita/followers","following_url":"https://api.github.com/users/KurnosovNikita/following{/other_user}","gists_url":"https://api.github.com/users/KurnosovNikita/gists{/gist_id}","starred_url":"https://api.github.com/users/KurnosovNikita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KurnosovNikita/subscriptions","organizations_url":"https://api.github.com/users/KurnosovNikita/orgs","repos_url":"https://api.github.com/users/KurnosovNikita/repos","events_url":"https://api.github.com/users/KurnosovNikita/events{/privacy}","received_events_url":"https://api.github.com/users/KurnosovNikita/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/KurnosovNikita/rsschool-api","description":null,"fork":true,"url":"https://api.github.com/repos/KurnosovNikita/rsschool-api","forks_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/forks","keys_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/teams","hooks_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/hooks","issue_events_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/issues/events{/number}","events_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/events","assignees_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/assignees{/user}","branches_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/branches{/branch}","tags_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/tags","blobs_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/statuses/{sha}","languages_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/languages","stargazers_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/stargazers","contributors_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/contributors","subscribers_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/subscribers","subscription_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/subscription","commits_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/contents/{+path}","compare_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/merges","archive_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/downloads","issues_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/issues{/number}","pulls_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/pulls{/number}","milestones_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/milestones{/number}","notifications_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/labels{/name}","releases_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/releases{/id}","deployments_url":"https://api.github.com/repos/KurnosovNikita/rsschool-api/deployments","created_at":"2018-08-06T16:21:01Z","updated_at":"2018-08-06T16:21:03Z","pushed_at":"2018-09-02T19:42:19Z","git_url":"git://github.com/KurnosovNikita/rsschool-api.git","ssh_url":"git@github.com:KurnosovNikita/rsschool-api.git","clone_url":"https://github.com/KurnosovNikita/rsschool-api.git","svn_url":"https://github.com/KurnosovNikita/rsschool-api","homepage":null,"size":246,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"rolling-scopes:master","ref":"master","sha":"dd20d984dc758080811231b472d14195fbcc66c9","user":{"login":"rolling-scopes","id":6222837,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYyMjI4Mzc=","avatar_url":"https://avatars3.githubusercontent.com/u/6222837?v=4","gravatar_id":"","url":"https://api.github.com/users/rolling-scopes","html_url":"https://github.com/rolling-scopes","followers_url":"https://api.github.com/users/rolling-scopes/followers","following_url":"https://api.github.com/users/rolling-scopes/following{/other_user}","gists_url":"https://api.github.com/users/rolling-scopes/gists{/gist_id}","starred_url":"https://api.github.com/users/rolling-scopes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rolling-scopes/subscriptions","organizations_url":"https://api.github.com/users/rolling-scopes/orgs","repos_url":"https://api.github.com/users/rolling-scopes/repos","events_url":"https://api.github.com/users/rolling-scopes/events{/privacy}","received_events_url":"https://api.github.com/users/rolling-scopes/received_events","type":"Organization","site_admin":false},"repo":{"id":134417832,"node_id":"MDEwOlJlcG9zaXRvcnkxMzQ0MTc4MzI=","name":"rsschool-api","full_name":"rolling-scopes/rsschool-api","owner":{"login":"rolling-scopes","id":6222837,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYyMjI4Mzc=","avatar_url":"https://avatars3.githubusercontent.com/u/6222837?v=4","gravatar_id":"","url":"https://api.github.com/users/rolling-scopes","html_url":"https://github.com/rolling-scopes","followers_url":"https://api.github.com/users/rolling-scopes/followers","following_url":"https://api.github.com/users/rolling-scopes/following{/other_user}","gists_url":"https://api.github.com/users/rolling-scopes/gists{/gist_id}","starred_url":"https://api.github.com/users/rolling-scopes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rolling-scopes/subscriptions","organizations_url":"https://api.github.com/users/rolling-scopes/orgs","repos_url":"https://api.github.com/users/rolling-scopes/repos","events_url":"https://api.github.com/users/rolling-scopes/events{/privacy}","received_events_url":"https://api.github.com/users/rolling-scopes/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rolling-scopes/rsschool-api","description":null,"fork":false,"url":"https://api.github.com/repos/rolling-scopes/rsschool-api","forks_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/forks","keys_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/teams","hooks_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/hooks","issue_events_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/issues/events{/number}","events_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/events","assignees_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/assignees{/user}","branches_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/branches{/branch}","tags_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/tags","blobs_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/statuses/{sha}","languages_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/languages","stargazers_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/stargazers","contributors_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/contributors","subscribers_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/subscribers","subscription_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/subscription","commits_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/contents/{+path}","compare_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/merges","archive_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/downloads","issues_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/issues{/number}","pulls_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls{/number}","milestones_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/milestones{/number}","notifications_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/labels{/name}","releases_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/releases{/id}","deployments_url":"https://api.github.com/repos/rolling-scopes/rsschool-api/deployments","created_at":"2018-05-22T13:18:23Z","updated_at":"2018-08-09T19:34:56Z","pushed_at":"2018-09-03T14:53:50Z","git_url":"git://github.com/rolling-scopes/rsschool-api.git","ssh_url":"git@github.com:rolling-scopes/rsschool-api.git","clone_url":"https://github.com/rolling-scopes/rsschool-api.git","svn_url":"https://github.com/rolling-scopes/rsschool-api","homepage":null,"size":219,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":44,"mirror_url":null,"archived":false,"open_issues_count":14,"license":null,"forks":44,"open_issues":14,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/17"},"html":{"href":"https://github.com/rolling-scopes/rsschool-api/pull/17"},"issue":{"href":"https://api.github.com/repos/rolling-scopes/rsschool-api/issues/17"},"comments":{"href":"https://api.github.com/repos/rolling-scopes/rsschool-api/issues/17/comments"},"review_comments":{"href":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/17/comments"},"review_comment":{"href":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rolling-scopes/rsschool-api/pulls/17/commits"},"statuses":{"href":"https://api.github.com/repos/rolling-scopes/rsschool-api/statuses/a31a6e80a0d07a5dc5f45e70bed764b5ef2b5c3c"}},"author_association":"NONE"}}
{"actor":{"display_login":"KurnosovNikita"}}