From a81c34b974f43ca4e2491796b174004cbb9fb33e Mon Sep 17 00:00:00 2001 From: Jack Heriz-Smith Date: Mon, 25 May 2020 13:17:45 +0100 Subject: [PATCH 1/2] Write database query Relates #19 Co-auhored-by: Hannah Gooding --- wip-rest-api/coverage/clover.xml | 28 +- wip-rest-api/coverage/coverage-final.json | 428 +++++++++++++++++- .../lcov-report/database/build.js.html | 4 +- .../lcov-report/database/connection.js.html | 2 +- .../coverage/lcov-report/database/index.html | 2 +- wip-rest-api/coverage/lcov-report/index.html | 30 +- .../lcov-report/model/feedback-model.js.html | 2 +- .../coverage/lcov-report/model/index.html | 29 +- .../lcov-report/model/users-model.js.html | 2 +- wip-rest-api/coverage/lcov.info | 28 +- wip-rest-api/src/database/init.sql | 5 +- wip-rest-api/src/model/projects-model.js | 27 ++ wip-rest-api/src/server.js | 3 +- wip-rest-api/src/test/db.test.js | 12 +- 14 files changed, 551 insertions(+), 51 deletions(-) diff --git a/wip-rest-api/coverage/clover.xml b/wip-rest-api/coverage/clover.xml index 03590df..69eed51 100644 --- a/wip-rest-api/coverage/clover.xml +++ b/wip-rest-api/coverage/clover.xml @@ -1,20 +1,20 @@ - - - + + + - + - + - + @@ -24,15 +24,25 @@ - - + + - + + + + + + + + + + + diff --git a/wip-rest-api/coverage/coverage-final.json b/wip-rest-api/coverage/coverage-final.json index 81a98ec..c69d94e 100644 --- a/wip-rest-api/coverage/coverage-final.json +++ b/wip-rest-api/coverage/coverage-final.json @@ -1,5 +1,425 @@ -{"/home/jackherizsmith/Desktop/FAC PROJECTS/10-studentproject/work-in-progress/wip-rest-api/src/database/build.js": {"path":"/home/jackherizsmith/Desktop/FAC PROJECTS/10-studentproject/work-in-progress/wip-rest-api/src/database/build.js","statementMap":{"0":{"start":{"line":1,"column":11},"end":{"line":1,"column":24}},"1":{"start":{"line":2,"column":13},"end":{"line":2,"column":28}},"2":{"start":{"line":3,"column":11},"end":{"line":3,"column":34}},"3":{"start":{"line":5,"column":17},"end":{"line":5,"column":49}},"4":{"start":{"line":6,"column":16},"end":{"line":6,"column":50}},"5":{"start":{"line":9,"column":2},"end":{"line":9,"column":27}},"6":{"start":{"line":12,"column":0},"end":{"line":12,"column":23}}},"fnMap":{"0":{"name":"build","decl":{"start":{"line":8,"column":9},"end":{"line":8,"column":14}},"loc":{"start":{"line":8,"column":17},"end":{"line":10,"column":1}},"line":8}},"branchMap":{},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":5,"6":1},"f":{"0":5},"b":{},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"de0558e80a3641648fa35f3c75b897698898d4d4"} -,"/home/jackherizsmith/Desktop/FAC PROJECTS/10-studentproject/work-in-progress/wip-rest-api/src/database/connection.js": {"path":"/home/jackherizsmith/Desktop/FAC PROJECTS/10-studentproject/work-in-progress/wip-rest-api/src/database/connection.js","statementMap":{"0":{"start":{"line":1,"column":11},"end":{"line":1,"column":24}},"1":{"start":{"line":2,"column":15},"end":{"line":2,"column":32}},"2":{"start":{"line":4,"column":0},"end":{"line":4,"column":16}},"3":{"start":{"line":6,"column":11},"end":{"line":10,"column":2}},"4":{"start":{"line":12,"column":0},"end":{"line":12,"column":20}}},"fnMap":{},"branchMap":{},"s":{"0":1,"1":1,"2":1,"3":1,"4":1},"f":{},"b":{},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"809077f1323ec3796f08dfe811d620f070b8ab6d"} -,"/home/jackherizsmith/Desktop/FAC PROJECTS/10-studentproject/work-in-progress/wip-rest-api/src/model/feedback-model.js": {"path":"/home/jackherizsmith/Desktop/FAC PROJECTS/10-studentproject/work-in-progress/wip-rest-api/src/model/feedback-model.js","statementMap":{"0":{"start":{"line":1,"column":11},"end":{"line":1,"column":47}},"1":{"start":{"line":4,"column":2},"end":{"line":6,"column":35}},"2":{"start":{"line":6,"column":22},"end":{"line":6,"column":33}},"3":{"start":{"line":9,"column":0},"end":{"line":11,"column":2}}},"fnMap":{"0":{"name":"getFeedback","decl":{"start":{"line":3,"column":9},"end":{"line":3,"column":20}},"loc":{"start":{"line":3,"column":29},"end":{"line":7,"column":1}},"line":3},"1":{"name":"(anonymous_1)","decl":{"start":{"line":6,"column":10},"end":{"line":6,"column":11}},"loc":{"start":{"line":6,"column":22},"end":{"line":6,"column":33}},"line":6}},"branchMap":{},"s":{"0":1,"1":1,"2":1,"3":1},"f":{"0":1,"1":1},"b":{},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"6b38a838d940be5637d6b1ab4dcd1496643c5e59"} -,"/home/jackherizsmith/Desktop/FAC PROJECTS/10-studentproject/work-in-progress/wip-rest-api/src/model/users-model.js": {"path":"/home/jackherizsmith/Desktop/FAC PROJECTS/10-studentproject/work-in-progress/wip-rest-api/src/model/users-model.js","statementMap":{"0":{"start":{"line":1,"column":11},"end":{"line":1,"column":47}},"1":{"start":{"line":10,"column":2},"end":{"line":15,"column":38}},"2":{"start":{"line":15,"column":22},"end":{"line":15,"column":36}},"3":{"start":{"line":20,"column":2},"end":{"line":22,"column":38}},"4":{"start":{"line":22,"column":22},"end":{"line":22,"column":36}},"5":{"start":{"line":27,"column":2},"end":{"line":29,"column":38}},"6":{"start":{"line":29,"column":22},"end":{"line":29,"column":36}},"7":{"start":{"line":34,"column":17},"end":{"line":41,"column":3}},"8":{"start":{"line":42,"column":2},"end":{"line":47,"column":38}},"9":{"start":{"line":47,"column":22},"end":{"line":47,"column":36}},"10":{"start":{"line":51,"column":2},"end":{"line":51,"column":63}},"11":{"start":{"line":54,"column":0},"end":{"line":61,"column":2}}},"fnMap":{"0":{"name":"addUser","decl":{"start":{"line":9,"column":9},"end":{"line":9,"column":16}},"loc":{"start":{"line":9,"column":63},"end":{"line":16,"column":1}},"line":9},"1":{"name":"(anonymous_1)","decl":{"start":{"line":15,"column":10},"end":{"line":15,"column":11}},"loc":{"start":{"line":15,"column":22},"end":{"line":15,"column":36}},"line":15},"2":{"name":"getUserByName","decl":{"start":{"line":19,"column":9},"end":{"line":19,"column":22}},"loc":{"start":{"line":19,"column":33},"end":{"line":23,"column":1}},"line":19},"3":{"name":"(anonymous_3)","decl":{"start":{"line":22,"column":10},"end":{"line":22,"column":11}},"loc":{"start":{"line":22,"column":22},"end":{"line":22,"column":36}},"line":22},"4":{"name":"getUserById","decl":{"start":{"line":26,"column":9},"end":{"line":26,"column":20}},"loc":{"start":{"line":26,"column":29},"end":{"line":30,"column":1}},"line":26},"5":{"name":"(anonymous_5)","decl":{"start":{"line":29,"column":10},"end":{"line":29,"column":11}},"loc":{"start":{"line":29,"column":22},"end":{"line":29,"column":36}},"line":29},"6":{"name":"updateUser","decl":{"start":{"line":33,"column":9},"end":{"line":33,"column":19}},"loc":{"start":{"line":33,"column":41},"end":{"line":48,"column":1}},"line":33},"7":{"name":"(anonymous_7)","decl":{"start":{"line":47,"column":10},"end":{"line":47,"column":11}},"loc":{"start":{"line":47,"column":22},"end":{"line":47,"column":36}},"line":47},"8":{"name":"deleteUser","decl":{"start":{"line":50,"column":9},"end":{"line":50,"column":19}},"loc":{"start":{"line":50,"column":28},"end":{"line":52,"column":1}},"line":50}},"branchMap":{},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":0,"11":1},"f":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":0},"b":{},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"78c4b882c3923342e3a227ef4ffd2752010e8660"} +{ + "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/database/build.js": { + "path": "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/database/build.js", + "statementMap": { + "0": { + "start": { "line": 1, "column": 11 }, + "end": { "line": 1, "column": 24 } + }, + "1": { + "start": { "line": 2, "column": 13 }, + "end": { "line": 2, "column": 28 } + }, + "2": { + "start": { "line": 3, "column": 11 }, + "end": { "line": 3, "column": 34 } + }, + "3": { + "start": { "line": 5, "column": 17 }, + "end": { "line": 5, "column": 49 } + }, + "4": { + "start": { "line": 6, "column": 16 }, + "end": { "line": 6, "column": 50 } + }, + "5": { + "start": { "line": 9, "column": 2 }, + "end": { "line": 9, "column": 27 } + }, + "6": { + "start": { "line": 12, "column": 0 }, + "end": { "line": 12, "column": 23 } + } + }, + "fnMap": { + "0": { + "name": "build", + "decl": { + "start": { "line": 8, "column": 9 }, + "end": { "line": 8, "column": 14 } + }, + "loc": { + "start": { "line": 8, "column": 17 }, + "end": { "line": 10, "column": 1 } + }, + "line": 8 + } + }, + "branchMap": {}, + "s": { "0": 1, "1": 1, "2": 1, "3": 1, "4": 1, "5": 6, "6": 1 }, + "f": { "0": 6 }, + "b": {}, + "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9", + "hash": "0b7c3d6c9b83b1aeb352477803d41713595a9232" + }, + "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/database/connection.js": { + "path": "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/database/connection.js", + "statementMap": { + "0": { + "start": { "line": 1, "column": 11 }, + "end": { "line": 1, "column": 24 } + }, + "1": { + "start": { "line": 2, "column": 15 }, + "end": { "line": 2, "column": 32 } + }, + "2": { + "start": { "line": 4, "column": 0 }, + "end": { "line": 4, "column": 16 } + }, + "3": { + "start": { "line": 6, "column": 11 }, + "end": { "line": 10, "column": 2 } + }, + "4": { + "start": { "line": 12, "column": 0 }, + "end": { "line": 12, "column": 20 } + } + }, + "fnMap": {}, + "branchMap": {}, + "s": { "0": 1, "1": 1, "2": 1, "3": 1, "4": 1 }, + "f": {}, + "b": {}, + "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9", + "hash": "ca748456ca18021640b2462b1cf184055559319a" + }, + "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/model/feedback-model.js": { + "path": "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/model/feedback-model.js", + "statementMap": { + "0": { + "start": { "line": 1, "column": 11 }, + "end": { "line": 1, "column": 47 } + }, + "1": { + "start": { "line": 4, "column": 2 }, + "end": { "line": 6, "column": 35 } + }, + "2": { + "start": { "line": 6, "column": 22 }, + "end": { "line": 6, "column": 33 } + }, + "3": { + "start": { "line": 9, "column": 0 }, + "end": { "line": 11, "column": 2 } + } + }, + "fnMap": { + "0": { + "name": "getFeedback", + "decl": { + "start": { "line": 3, "column": 9 }, + "end": { "line": 3, "column": 20 } + }, + "loc": { + "start": { "line": 3, "column": 29 }, + "end": { "line": 7, "column": 1 } + }, + "line": 3 + }, + "1": { + "name": "(anonymous_1)", + "decl": { + "start": { "line": 6, "column": 10 }, + "end": { "line": 6, "column": 11 } + }, + "loc": { + "start": { "line": 6, "column": 22 }, + "end": { "line": 6, "column": 33 } + }, + "line": 6 + } + }, + "branchMap": {}, + "s": { "0": 1, "1": 1, "2": 1, "3": 1 }, + "f": { "0": 1, "1": 1 }, + "b": {}, + "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9", + "hash": "5f2bfca9370933aa2877c82e5f05fa805f65e864" + }, + "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/model/projects-model.js": { + "path": "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/model/projects-model.js", + "statementMap": { + "0": { + "start": { "line": 1, "column": 11 }, + "end": { "line": 1, "column": 47 } + }, + "1": { + "start": { "line": 16, "column": 2 }, + "end": { "line": 22, "column": 37 } + }, + "2": { + "start": { "line": 19, "column": 29 }, + "end": { "line": 19, "column": 102 } + }, + "3": { + "start": { "line": 19, "column": 68 }, + "end": { "line": 19, "column": 101 } + }, + "4": { + "start": { "line": 20, "column": 10 }, + "end": { "line": 20, "column": 33 } + }, + "5": { + "start": { "line": 21, "column": 10 }, + "end": { "line": 21, "column": 92 } + }, + "6": { + "start": { "line": 22, "column": 24 }, + "end": { "line": 22, "column": 35 } + }, + "7": { + "start": { "line": 25, "column": 0 }, + "end": { "line": 27, "column": 2 } + } + }, + "fnMap": { + "0": { + "name": "getWatchedProjects", + "decl": { + "start": { "line": 15, "column": 9 }, + "end": { "line": 15, "column": 27 } + }, + "loc": { + "start": { "line": 15, "column": 36 }, + "end": { "line": 23, "column": 1 } + }, + "line": 15 + }, + "1": { + "name": "(anonymous_1)", + "decl": { + "start": { "line": 18, "column": 12 }, + "end": { "line": 18, "column": 13 } + }, + "loc": { + "start": { "line": 18, "column": 31 }, + "end": { "line": 22, "column": 7 } + }, + "line": 18 + }, + "2": { + "name": "(anonymous_2)", + "decl": { + "start": { "line": 19, "column": 52 }, + "end": { "line": 19, "column": 53 } + }, + "loc": { + "start": { "line": 19, "column": 68 }, + "end": { "line": 19, "column": 101 } + }, + "line": 19 + }, + "3": { + "name": "(anonymous_3)", + "decl": { + "start": { "line": 22, "column": 14 }, + "end": { "line": 22, "column": 15 } + }, + "loc": { + "start": { "line": 22, "column": 24 }, + "end": { "line": 22, "column": 35 } + }, + "line": 22 + } + }, + "branchMap": {}, + "s": { "0": 1, "1": 1, "2": 1, "3": 4, "4": 1, "5": 1, "6": 1, "7": 1 }, + "f": { "0": 1, "1": 1, "2": 4, "3": 1 }, + "b": {}, + "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9", + "hash": "51e3a621bdd4a2809ecc3dbc96981aae8ac7346e" + }, + "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/model/users-model.js": { + "path": "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/model/users-model.js", + "statementMap": { + "0": { + "start": { "line": 1, "column": 11 }, + "end": { "line": 1, "column": 47 } + }, + "1": { + "start": { "line": 10, "column": 2 }, + "end": { "line": 15, "column": 38 } + }, + "2": { + "start": { "line": 15, "column": 22 }, + "end": { "line": 15, "column": 36 } + }, + "3": { + "start": { "line": 20, "column": 2 }, + "end": { "line": 22, "column": 38 } + }, + "4": { + "start": { "line": 22, "column": 22 }, + "end": { "line": 22, "column": 36 } + }, + "5": { + "start": { "line": 27, "column": 2 }, + "end": { "line": 29, "column": 38 } + }, + "6": { + "start": { "line": 29, "column": 22 }, + "end": { "line": 29, "column": 36 } + }, + "7": { + "start": { "line": 34, "column": 17 }, + "end": { "line": 41, "column": 3 } + }, + "8": { + "start": { "line": 42, "column": 2 }, + "end": { "line": 47, "column": 38 } + }, + "9": { + "start": { "line": 47, "column": 22 }, + "end": { "line": 47, "column": 36 } + }, + "10": { + "start": { "line": 51, "column": 2 }, + "end": { "line": 51, "column": 63 } + }, + "11": { + "start": { "line": 54, "column": 0 }, + "end": { "line": 61, "column": 2 } + } + }, + "fnMap": { + "0": { + "name": "addUser", + "decl": { + "start": { "line": 9, "column": 9 }, + "end": { "line": 9, "column": 16 } + }, + "loc": { + "start": { "line": 9, "column": 63 }, + "end": { "line": 16, "column": 1 } + }, + "line": 9 + }, + "1": { + "name": "(anonymous_1)", + "decl": { + "start": { "line": 15, "column": 10 }, + "end": { "line": 15, "column": 11 } + }, + "loc": { + "start": { "line": 15, "column": 22 }, + "end": { "line": 15, "column": 36 } + }, + "line": 15 + }, + "2": { + "name": "getUserByName", + "decl": { + "start": { "line": 19, "column": 9 }, + "end": { "line": 19, "column": 22 } + }, + "loc": { + "start": { "line": 19, "column": 33 }, + "end": { "line": 23, "column": 1 } + }, + "line": 19 + }, + "3": { + "name": "(anonymous_3)", + "decl": { + "start": { "line": 22, "column": 10 }, + "end": { "line": 22, "column": 11 } + }, + "loc": { + "start": { "line": 22, "column": 22 }, + "end": { "line": 22, "column": 36 } + }, + "line": 22 + }, + "4": { + "name": "getUserById", + "decl": { + "start": { "line": 26, "column": 9 }, + "end": { "line": 26, "column": 20 } + }, + "loc": { + "start": { "line": 26, "column": 29 }, + "end": { "line": 30, "column": 1 } + }, + "line": 26 + }, + "5": { + "name": "(anonymous_5)", + "decl": { + "start": { "line": 29, "column": 10 }, + "end": { "line": 29, "column": 11 } + }, + "loc": { + "start": { "line": 29, "column": 22 }, + "end": { "line": 29, "column": 36 } + }, + "line": 29 + }, + "6": { + "name": "updateUser", + "decl": { + "start": { "line": 33, "column": 9 }, + "end": { "line": 33, "column": 19 } + }, + "loc": { + "start": { "line": 33, "column": 41 }, + "end": { "line": 48, "column": 1 } + }, + "line": 33 + }, + "7": { + "name": "(anonymous_7)", + "decl": { + "start": { "line": 47, "column": 10 }, + "end": { "line": 47, "column": 11 } + }, + "loc": { + "start": { "line": 47, "column": 22 }, + "end": { "line": 47, "column": 36 } + }, + "line": 47 + }, + "8": { + "name": "deleteUser", + "decl": { + "start": { "line": 50, "column": 9 }, + "end": { "line": 50, "column": 19 } + }, + "loc": { + "start": { "line": 50, "column": 28 }, + "end": { "line": 52, "column": 1 } + }, + "line": 50 + } + }, + "branchMap": {}, + "s": { + "0": 1, + "1": 1, + "2": 1, + "3": 1, + "4": 1, + "5": 1, + "6": 1, + "7": 1, + "8": 1, + "9": 1, + "10": 0, + "11": 1 + }, + "f": { + "0": 1, + "1": 1, + "2": 1, + "3": 1, + "4": 1, + "5": 1, + "6": 1, + "7": 1, + "8": 0 + }, + "b": {}, + "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9", + "hash": "21864568a55a6250042f97b6f6d92d32a8e31263" + } } diff --git a/wip-rest-api/coverage/lcov-report/database/build.js.html b/wip-rest-api/coverage/lcov-report/database/build.js.html index 3845ad9..2d9c7f4 100644 --- a/wip-rest-api/coverage/lcov-report/database/build.js.html +++ b/wip-rest-api/coverage/lcov-report/database/build.js.html @@ -77,7 +77,7 @@

All files / database bu 1x     -5x +6x     1x @@ -100,7 +100,7 @@

All files / database bu diff --git a/wip-rest-api/coverage/lcov-report/database/connection.js.html b/wip-rest-api/coverage/lcov-report/database/connection.js.html index d1a7d86..5916e1b 100644 --- a/wip-rest-api/coverage/lcov-report/database/connection.js.html +++ b/wip-rest-api/coverage/lcov-report/database/connection.js.html @@ -100,7 +100,7 @@

All files / database co diff --git a/wip-rest-api/coverage/lcov-report/database/index.html b/wip-rest-api/coverage/lcov-report/database/index.html index b68c8ea..214ab2f 100644 --- a/wip-rest-api/coverage/lcov-report/database/index.html +++ b/wip-rest-api/coverage/lcov-report/database/index.html @@ -110,7 +110,7 @@

All files database

diff --git a/wip-rest-api/coverage/lcov-report/index.html b/wip-rest-api/coverage/lcov-report/index.html index 1b1781b..5aaed30 100644 --- a/wip-rest-api/coverage/lcov-report/index.html +++ b/wip-rest-api/coverage/lcov-report/index.html @@ -23,9 +23,9 @@

All files

- 96.43% + 97.22% Statements - 27/28 + 35/36
@@ -37,16 +37,16 @@

All files

- 91.67% + 93.75% Functions - 11/12 + 15/16
- 96.43% + 97.14% Lines - 27/28 + 34/35
@@ -89,17 +89,17 @@

All files

model - -
+ +
- 93.75% - 15/16 + 95.83% + 23/24 100% 0/0 - 90.91% - 10/11 - 93.75% - 15/16 + 93.33% + 14/15 + 95.65% + 22/23 @@ -110,7 +110,7 @@

All files

diff --git a/wip-rest-api/coverage/lcov-report/model/feedback-model.js.html b/wip-rest-api/coverage/lcov-report/model/feedback-model.js.html index 3e0bb97..a28f63f 100644 --- a/wip-rest-api/coverage/lcov-report/model/feedback-model.js.html +++ b/wip-rest-api/coverage/lcov-report/model/feedback-model.js.html @@ -97,7 +97,7 @@

All files / model feedb diff --git a/wip-rest-api/coverage/lcov-report/model/index.html b/wip-rest-api/coverage/lcov-report/model/index.html index a0a1fed..bcb7a67 100644 --- a/wip-rest-api/coverage/lcov-report/model/index.html +++ b/wip-rest-api/coverage/lcov-report/model/index.html @@ -23,9 +23,9 @@

All files model

- 93.75% + 95.83% Statements - 15/16 + 23/24
@@ -37,16 +37,16 @@

All files model

- 90.91% + 93.33% Functions - 10/11 + 14/15
- 93.75% + 95.65% Lines - 15/16 + 22/23
@@ -87,6 +87,21 @@

All files model

4/4 + + projects-model.js + +
+ + 100% + 8/8 + 100% + 0/0 + 100% + 4/4 + 100% + 7/7 + + users-model.js @@ -110,7 +125,7 @@

All files model

diff --git a/wip-rest-api/coverage/lcov-report/model/users-model.js.html b/wip-rest-api/coverage/lcov-report/model/users-model.js.html index 4f2d729..ff15b1f 100644 --- a/wip-rest-api/coverage/lcov-report/model/users-model.js.html +++ b/wip-rest-api/coverage/lcov-report/model/users-model.js.html @@ -247,7 +247,7 @@

All files / model users diff --git a/wip-rest-api/coverage/lcov.info b/wip-rest-api/coverage/lcov.info index 13c0fe4..d9c228e 100644 --- a/wip-rest-api/coverage/lcov.info +++ b/wip-rest-api/coverage/lcov.info @@ -3,13 +3,13 @@ SF:src/database/build.js FN:8,build FNF:1 FNH:1 -FNDA:5,build +FNDA:6,build DA:1,1 DA:2,1 DA:3,1 DA:5,1 DA:6,1 -DA:9,5 +DA:9,6 DA:12,1 LF:7 LH:7 @@ -48,6 +48,30 @@ BRF:0 BRH:0 end_of_record TN: +SF:src/model/projects-model.js +FN:15,getWatchedProjects +FN:18,(anonymous_1) +FN:19,(anonymous_2) +FN:22,(anonymous_3) +FNF:4 +FNH:4 +FNDA:1,getWatchedProjects +FNDA:1,(anonymous_1) +FNDA:4,(anonymous_2) +FNDA:1,(anonymous_3) +DA:1,1 +DA:16,1 +DA:19,4 +DA:20,1 +DA:21,1 +DA:22,1 +DA:25,1 +LF:7 +LH:7 +BRF:0 +BRH:0 +end_of_record +TN: SF:src/model/users-model.js FN:9,addUser FN:15,(anonymous_1) diff --git a/wip-rest-api/src/database/init.sql b/wip-rest-api/src/database/init.sql index 21a7d2a..2afce9e 100644 --- a/wip-rest-api/src/database/init.sql +++ b/wip-rest-api/src/database/init.sql @@ -91,8 +91,11 @@ BEGIN; (user_id, project_id) VALUES ('1', '2'), - ('3', '3'), + ('2', '1'), + ('2', '2'), + ('2', '4'), ('2', '5'), + ('3', '3'), ('4', '4'); END; \ No newline at end of file diff --git a/wip-rest-api/src/model/projects-model.js b/wip-rest-api/src/model/projects-model.js index e69de29..5fa1053 100644 --- a/wip-rest-api/src/model/projects-model.js +++ b/wip-rest-api/src/model/projects-model.js @@ -0,0 +1,27 @@ +const db = require("../database/connection.js"); + +// function getMultipleBooksById(ids) { +// const sqlVariableList = ids.map((id, index) => { +// return `$${index + 1}`; +// }); +// return db +// .query(`SELECT title FROM books WHERE id IN (${sqlVariableList});`, ids) +// .then((res) => res.rows); +// } + + +// SELECT * FROM projects WHERE id IN (${list}), [ids]) + +function getWatchedProjects(userId) { + return db + .query("SELECT project_id FROM user_watch WHERE user_id=($1);", [userId]) + .then((projectIdObjs) => { + const projectIds = projectIdObjs.rows.map(projectIdObj => parseInt(projectIdObj.project_id)) + console.log(projectIds) + return db.query("SELECT * FROM projects WHERE id IN ($1, $2, $3, $4)", projectIds) + }).then(result => result.rows); +} + +module.exports = { + getWatchedProjects, +}; diff --git a/wip-rest-api/src/server.js b/wip-rest-api/src/server.js index 5050b9a..6b2d7e8 100644 --- a/wip-rest-api/src/server.js +++ b/wip-rest-api/src/server.js @@ -25,7 +25,8 @@ server.put("/user", checkAuth, users.put); // server.delete("/user/:username", checkAuth, users.delete); //Routes for projects -server.get("/project/:projectId", checkAuth, project.get); +server.get("/feed/:userId", checkAuth, project.get); +// server.get("/project/:projectId", checkAuth, project.get); // server.post('project', auth, project.post) // server.put('/project/:projectId', auth, project.put) // server.delete('/project/:projectId', auth, project.delete) diff --git a/wip-rest-api/src/test/db.test.js b/wip-rest-api/src/test/db.test.js index 3f7cf53..05880cb 100644 --- a/wip-rest-api/src/test/db.test.js +++ b/wip-rest-api/src/test/db.test.js @@ -1,4 +1,4 @@ -const dbconnection = require("../database/connection"); +const dbconnection = require("../database/connection.js"); const build = require("../database/build"); const { // getUsers, @@ -9,6 +9,8 @@ const { // deleteUser, } = require("../model/users-model"); +const { getWatchedProjects } = require("../model/projects-model"); + const { getFeedback } = require("../model/feedback-model"); afterAll(() => { @@ -91,11 +93,9 @@ describe("Database tests for projects", () => { build(); }); - test("Get feedback from database using stepId", async () => { - await getFeedback("2").then((feedback) => { - expect(feedback[0].feedback_text).toEqual( - "Hey Han its Cam what a nice dog" - ); + test("Get all watched projects", async () => { + await getWatchedProjects("2").then((projects) => { + expect(projects.length).toEqual(4); }); }); }); From 3b36bc255a5383ea2c426d235e45fa4b716c83d5 Mon Sep 17 00:00:00 2001 From: Jack Heriz-Smith Date: Mon, 25 May 2020 14:06:52 +0100 Subject: [PATCH 2/2] Write database query Relates #19 Co-auhored-by: Hannah Gooding --- wip-rest-api/.travis.yaml | 6 -- wip-rest-api/coverage/clover.xml | 21 ++--- wip-rest-api/coverage/coverage-final.json | 82 +++++-------------- .../lcov-report/database/build.js.html | 4 +- .../lcov-report/database/connection.js.html | 2 +- .../coverage/lcov-report/database/index.html | 2 +- wip-rest-api/coverage/lcov-report/index.html | 28 +++---- .../lcov-report/model/feedback-model.js.html | 2 +- .../coverage/lcov-report/model/index.html | 20 ++--- .../lcov-report/model/users-model.js.html | 2 +- wip-rest-api/coverage/lcov.info | 33 +++----- wip-rest-api/src/model/projects-model.js | 22 +---- wip-rest-api/src/test/db.test.js | 8 +- 13 files changed, 83 insertions(+), 149 deletions(-) delete mode 100644 wip-rest-api/.travis.yaml diff --git a/wip-rest-api/.travis.yaml b/wip-rest-api/.travis.yaml deleted file mode 100644 index bb0a25d..0000000 --- a/wip-rest-api/.travis.yaml +++ /dev/null @@ -1,6 +0,0 @@ -language: - node_js -install: - - npm install -g codecov -script: - - codecov \ No newline at end of file diff --git a/wip-rest-api/coverage/clover.xml b/wip-rest-api/coverage/clover.xml index 69eed51..9df9b42 100644 --- a/wip-rest-api/coverage/clover.xml +++ b/wip-rest-api/coverage/clover.xml @@ -1,7 +1,7 @@ - - - + + + @@ -11,7 +11,7 @@ - + @@ -24,7 +24,7 @@ - + @@ -33,14 +33,11 @@ - + - - - - - - + + + diff --git a/wip-rest-api/coverage/coverage-final.json b/wip-rest-api/coverage/coverage-final.json index c69d94e..b19d14a 100644 --- a/wip-rest-api/coverage/coverage-final.json +++ b/wip-rest-api/coverage/coverage-final.json @@ -46,8 +46,8 @@ } }, "branchMap": {}, - "s": { "0": 1, "1": 1, "2": 1, "3": 1, "4": 1, "5": 6, "6": 1 }, - "f": { "0": 6 }, + "s": { "0": 1, "1": 1, "2": 1, "3": 1, "4": 1, "5": 7, "6": 1 }, + "f": { "0": 7 }, "b": {}, "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9", "hash": "0b7c3d6c9b83b1aeb352477803d41713595a9232" @@ -145,90 +145,50 @@ "end": { "line": 1, "column": 47 } }, "1": { - "start": { "line": 16, "column": 2 }, - "end": { "line": 22, "column": 37 } + "start": { "line": 4, "column": 2 }, + "end": { "line": 6, "column": 31 } }, "2": { - "start": { "line": 19, "column": 29 }, - "end": { "line": 19, "column": 102 } + "start": { "line": 6, "column": 18 }, + "end": { "line": 6, "column": 29 } }, "3": { - "start": { "line": 19, "column": 68 }, - "end": { "line": 19, "column": 101 } - }, - "4": { - "start": { "line": 20, "column": 10 }, - "end": { "line": 20, "column": 33 } - }, - "5": { - "start": { "line": 21, "column": 10 }, - "end": { "line": 21, "column": 92 } - }, - "6": { - "start": { "line": 22, "column": 24 }, - "end": { "line": 22, "column": 35 } - }, - "7": { - "start": { "line": 25, "column": 0 }, - "end": { "line": 27, "column": 2 } + "start": { "line": 9, "column": 0 }, + "end": { "line": 11, "column": 2 } } }, "fnMap": { "0": { "name": "getWatchedProjects", "decl": { - "start": { "line": 15, "column": 9 }, - "end": { "line": 15, "column": 27 } + "start": { "line": 3, "column": 9 }, + "end": { "line": 3, "column": 27 } }, "loc": { - "start": { "line": 15, "column": 36 }, - "end": { "line": 23, "column": 1 } + "start": { "line": 3, "column": 36 }, + "end": { "line": 7, "column": 1 } }, - "line": 15 + "line": 3 }, "1": { "name": "(anonymous_1)", "decl": { - "start": { "line": 18, "column": 12 }, - "end": { "line": 18, "column": 13 } + "start": { "line": 6, "column": 8 }, + "end": { "line": 6, "column": 9 } }, "loc": { - "start": { "line": 18, "column": 31 }, - "end": { "line": 22, "column": 7 } + "start": { "line": 6, "column": 18 }, + "end": { "line": 6, "column": 29 } }, - "line": 18 - }, - "2": { - "name": "(anonymous_2)", - "decl": { - "start": { "line": 19, "column": 52 }, - "end": { "line": 19, "column": 53 } - }, - "loc": { - "start": { "line": 19, "column": 68 }, - "end": { "line": 19, "column": 101 } - }, - "line": 19 - }, - "3": { - "name": "(anonymous_3)", - "decl": { - "start": { "line": 22, "column": 14 }, - "end": { "line": 22, "column": 15 } - }, - "loc": { - "start": { "line": 22, "column": 24 }, - "end": { "line": 22, "column": 35 } - }, - "line": 22 + "line": 6 } }, "branchMap": {}, - "s": { "0": 1, "1": 1, "2": 1, "3": 4, "4": 1, "5": 1, "6": 1, "7": 1 }, - "f": { "0": 1, "1": 1, "2": 4, "3": 1 }, + "s": { "0": 1, "1": 2, "2": 2, "3": 1 }, + "f": { "0": 2, "1": 2 }, "b": {}, "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9", - "hash": "51e3a621bdd4a2809ecc3dbc96981aae8ac7346e" + "hash": "d5323d57eba399fe9c285a8a53227684051aecd5" }, "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/model/users-model.js": { "path": "/home/jackherizsmith/Desktop/code/10-studentproject/work-in-progress/wip-rest-api/src/model/users-model.js", diff --git a/wip-rest-api/coverage/lcov-report/database/build.js.html b/wip-rest-api/coverage/lcov-report/database/build.js.html index 2d9c7f4..798c7ea 100644 --- a/wip-rest-api/coverage/lcov-report/database/build.js.html +++ b/wip-rest-api/coverage/lcov-report/database/build.js.html @@ -77,7 +77,7 @@

All files / database bu 1x     -6x +7x     1x @@ -100,7 +100,7 @@

All files / database bu diff --git a/wip-rest-api/coverage/lcov-report/database/connection.js.html b/wip-rest-api/coverage/lcov-report/database/connection.js.html index 5916e1b..baa7746 100644 --- a/wip-rest-api/coverage/lcov-report/database/connection.js.html +++ b/wip-rest-api/coverage/lcov-report/database/connection.js.html @@ -100,7 +100,7 @@

All files / database co diff --git a/wip-rest-api/coverage/lcov-report/database/index.html b/wip-rest-api/coverage/lcov-report/database/index.html index 214ab2f..3aab275 100644 --- a/wip-rest-api/coverage/lcov-report/database/index.html +++ b/wip-rest-api/coverage/lcov-report/database/index.html @@ -110,7 +110,7 @@

All files database

diff --git a/wip-rest-api/coverage/lcov-report/index.html b/wip-rest-api/coverage/lcov-report/index.html index 5aaed30..1986923 100644 --- a/wip-rest-api/coverage/lcov-report/index.html +++ b/wip-rest-api/coverage/lcov-report/index.html @@ -23,9 +23,9 @@

All files

- 97.22% + 96.88% Statements - 35/36 + 31/32
@@ -37,16 +37,16 @@

All files

- 93.75% + 92.86% Functions - 15/16 + 13/14
- 97.14% + 96.88% Lines - 34/35 + 31/32
@@ -89,17 +89,17 @@

All files

model - +
- 95.83% - 23/24 + 95% + 19/20 100% 0/0 - 93.33% - 14/15 - 95.65% - 22/23 + 92.31% + 12/13 + 95% + 19/20 @@ -110,7 +110,7 @@

All files

diff --git a/wip-rest-api/coverage/lcov-report/model/feedback-model.js.html b/wip-rest-api/coverage/lcov-report/model/feedback-model.js.html index a28f63f..145a965 100644 --- a/wip-rest-api/coverage/lcov-report/model/feedback-model.js.html +++ b/wip-rest-api/coverage/lcov-report/model/feedback-model.js.html @@ -97,7 +97,7 @@

All files / model feedb diff --git a/wip-rest-api/coverage/lcov-report/model/index.html b/wip-rest-api/coverage/lcov-report/model/index.html index bcb7a67..a6fed21 100644 --- a/wip-rest-api/coverage/lcov-report/model/index.html +++ b/wip-rest-api/coverage/lcov-report/model/index.html @@ -23,9 +23,9 @@

All files model

- 95.83% + 95% Statements - 23/24 + 19/20
@@ -37,16 +37,16 @@

All files model

- 93.33% + 92.31% Functions - 14/15 + 12/13
- 95.65% + 95% Lines - 22/23 + 19/20
@@ -93,13 +93,13 @@

All files model

100% - 8/8 + 4/4 100% 0/0 100% - 4/4 + 2/2 100% - 7/7 + 4/4 @@ -125,7 +125,7 @@

All files model

diff --git a/wip-rest-api/coverage/lcov-report/model/users-model.js.html b/wip-rest-api/coverage/lcov-report/model/users-model.js.html index ff15b1f..0389248 100644 --- a/wip-rest-api/coverage/lcov-report/model/users-model.js.html +++ b/wip-rest-api/coverage/lcov-report/model/users-model.js.html @@ -247,7 +247,7 @@

All files / model users diff --git a/wip-rest-api/coverage/lcov.info b/wip-rest-api/coverage/lcov.info index d9c228e..ee58f5c 100644 --- a/wip-rest-api/coverage/lcov.info +++ b/wip-rest-api/coverage/lcov.info @@ -3,13 +3,13 @@ SF:src/database/build.js FN:8,build FNF:1 FNH:1 -FNDA:6,build +FNDA:7,build DA:1,1 DA:2,1 DA:3,1 DA:5,1 DA:6,1 -DA:9,6 +DA:9,7 DA:12,1 LF:7 LH:7 @@ -49,25 +49,18 @@ BRH:0 end_of_record TN: SF:src/model/projects-model.js -FN:15,getWatchedProjects -FN:18,(anonymous_1) -FN:19,(anonymous_2) -FN:22,(anonymous_3) -FNF:4 -FNH:4 -FNDA:1,getWatchedProjects -FNDA:1,(anonymous_1) -FNDA:4,(anonymous_2) -FNDA:1,(anonymous_3) +FN:3,getWatchedProjects +FN:6,(anonymous_1) +FNF:2 +FNH:2 +FNDA:2,getWatchedProjects +FNDA:2,(anonymous_1) DA:1,1 -DA:16,1 -DA:19,4 -DA:20,1 -DA:21,1 -DA:22,1 -DA:25,1 -LF:7 -LH:7 +DA:4,2 +DA:6,2 +DA:9,1 +LF:4 +LH:4 BRF:0 BRH:0 end_of_record diff --git a/wip-rest-api/src/model/projects-model.js b/wip-rest-api/src/model/projects-model.js index 5fa1053..8f2865d 100644 --- a/wip-rest-api/src/model/projects-model.js +++ b/wip-rest-api/src/model/projects-model.js @@ -1,27 +1,11 @@ const db = require("../database/connection.js"); -// function getMultipleBooksById(ids) { -// const sqlVariableList = ids.map((id, index) => { -// return `$${index + 1}`; -// }); -// return db -// .query(`SELECT title FROM books WHERE id IN (${sqlVariableList});`, ids) -// .then((res) => res.rows); -// } - - -// SELECT * FROM projects WHERE id IN (${list}), [ids]) - function getWatchedProjects(userId) { return db - .query("SELECT project_id FROM user_watch WHERE user_id=($1);", [userId]) - .then((projectIdObjs) => { - const projectIds = projectIdObjs.rows.map(projectIdObj => parseInt(projectIdObj.project_id)) - console.log(projectIds) - return db.query("SELECT * FROM projects WHERE id IN ($1, $2, $3, $4)", projectIds) - }).then(result => result.rows); + .query("SELECT * FROM projects JOIN user_watch ON projects.id=user_watch.project_id WHERE user_watch.user_id=($1);",[userId]) + .then(result => result.rows); } module.exports = { getWatchedProjects, -}; +}; \ No newline at end of file diff --git a/wip-rest-api/src/test/db.test.js b/wip-rest-api/src/test/db.test.js index 05880cb..a6f2e4b 100644 --- a/wip-rest-api/src/test/db.test.js +++ b/wip-rest-api/src/test/db.test.js @@ -93,11 +93,17 @@ describe("Database tests for projects", () => { build(); }); - test("Get all watched projects", async () => { + test("Get all watched projects returns array of correct length", async () => { await getWatchedProjects("2").then((projects) => { expect(projects.length).toEqual(4); }); }); + + test("Get info from watched projects", async () => { + await getWatchedProjects("2").then((projects) => { + expect(projects[2].project_name).toEqual('A friend'); + }); + }); }); describe("Database tests for feedback", () => {