From 6fc3cdd5fc13eea63f2d36e3313dff11dda75b49 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Tue, 11 Feb 2020 12:17:56 +0100 Subject: [PATCH 01/21] change Users table --- data/migrations/20191217151137_users-table.js | 6 ++- .../20191217151436_interviewers-table.js | 40 +++++++++---------- .../20191217151549_interviewees-table.js | 34 ++++++++-------- .../migrations/20200103203521_appointments.js | 6 +-- .../appointments/appointments-router.js | 1 - src/resources/profiles/profile-controllers.js | 2 +- src/resources/profiles/profile-models.js | 4 +- 7 files changed, 48 insertions(+), 45 deletions(-) diff --git a/data/migrations/20191217151137_users-table.js b/data/migrations/20191217151137_users-table.js index 7b474a6..42f0fe3 100644 --- a/data/migrations/20191217151137_users-table.js +++ b/data/migrations/20191217151137_users-table.js @@ -5,10 +5,14 @@ exports.up = function(knex) { table.string('last_name', 128).notNullable(); table.string('email', 128).notNullable().unique(); table.string('password', 128).notNullable(); - table.string('location'); table.string('avatar_url', 256).defaultTo(''); table.string('github', 128).defaultTo(null); table.string('linkedin', 128).defaultTo(null); + table.string('description', 400); + table.integer('experience_level').notNullable(); + table.string('location'); + table.integer('rating'); + table.float('hourly_rate'); table .integer('role_id') .defaultTo(null) diff --git a/data/migrations/20191217151436_interviewers-table.js b/data/migrations/20191217151436_interviewers-table.js index 87cf7f2..6f944b0 100644 --- a/data/migrations/20191217151436_interviewers-table.js +++ b/data/migrations/20191217151436_interviewers-table.js @@ -1,21 +1,21 @@ -exports.up = function(knex) { - return knex.schema.createTable('coaches', table => { - table.increments(); - table - .integer('user_id') - .unsigned() - .unique() - .notNullable() - .references('id') - .inTable('users'); - table.integer('experience_level').notNullable(); - table.integer('skill_level').notNullable(); - table.string('description', 400); - table.integer('rating'); - table.float('hourly_rate'); - }); -}; +// exports.up = function(knex) { +// return knex.schema.createTable('coaches', table => { +// table.increments(); +// table +// .integer('user_id') +// .unsigned() +// .unique() +// .notNullable() +// .references('id') +// .inTable('users'); +// table.integer('experience_level').notNullable(); +// table.integer('skill_level').notNullable(); +// table.string('description', 400); +// table.integer('rating'); +// table.float('hourly_rate'); +// }); +// }; -exports.down = function(knex) { - return knex.schema.dropTableIfExists('coaches'); -}; +// exports.down = function(knex) { +// return knex.schema.dropTableIfExists('coaches'); +// }; diff --git a/data/migrations/20191217151549_interviewees-table.js b/data/migrations/20191217151549_interviewees-table.js index 5768b48..718e6c0 100644 --- a/data/migrations/20191217151549_interviewees-table.js +++ b/data/migrations/20191217151549_interviewees-table.js @@ -1,18 +1,18 @@ -exports.up = function(knex) { - return knex.schema.createTable('students', table => { - table.increments(); - table - .integer('user_id') - .unsigned() - .unique() - .notNullable() - .references('id') - .inTable('users'); - table.integer('experience_level').notNullable(); - table.integer('confidence_level').notNullable(); - }); -}; +// exports.up = function(knex) { +// return knex.schema.createTable('students', table => { +// table.increments(); +// table +// .integer('user_id') +// .unsigned() +// .unique() +// .notNullable() +// .references('id') +// .inTable('users'); +// table.integer('experience_level').notNullable(); +// table.integer('confidence_level').notNullable(); +// }); +// }; -exports.down = function(knex) { - return knex.schema.dropTableIfExists('students'); -}; +// exports.down = function(knex) { +// return knex.schema.dropTableIfExists('students'); +// }; diff --git a/data/migrations/20200103203521_appointments.js b/data/migrations/20200103203521_appointments.js index a60a8a8..c9ed34e 100644 --- a/data/migrations/20200103203521_appointments.js +++ b/data/migrations/20200103203521_appointments.js @@ -5,13 +5,13 @@ exports.up = function(knex) { table.boolean('canceled').defaultTo(false); table.boolean('finished').defaultTo(false); table - .integer('coach_id') + .integer('user_id_one') .notNullable() .unsigned() .references('id') - .inTable('coaches'); + .inTable('users'); table - .integer('student_id') + .integer('user_id_two') .notNullable() .unsigned() .references('id') diff --git a/src/resources/appointments/appointments-router.js b/src/resources/appointments/appointments-router.js index 44a193d..d6de0c9 100644 --- a/src/resources/appointments/appointments-router.js +++ b/src/resources/appointments/appointments-router.js @@ -8,7 +8,6 @@ router.get('/:id', checkAuth, appointmentsController.appointments); router.post('/', checkAuth, appointmentsController.addAppointment); router.put( '/:id', - checkAuth, appointmentsController.updateAppointment, ); // appointment/appointment_id diff --git a/src/resources/profiles/profile-controllers.js b/src/resources/profiles/profile-controllers.js index 43aadc1..29eb6fb 100644 --- a/src/resources/profiles/profile-controllers.js +++ b/src/resources/profiles/profile-controllers.js @@ -56,7 +56,7 @@ exports.addCoach = async (req, res) => { exports.updateCoach = async (req, res) => { try { const coach = await Profile.update( - req.body.hourly_rate, + req.body.rating, req.params.id, ); if (coach) { diff --git a/src/resources/profiles/profile-models.js b/src/resources/profiles/profile-models.js index 954e43f..b4ed950 100644 --- a/src/resources/profiles/profile-models.js +++ b/src/resources/profiles/profile-models.js @@ -20,10 +20,10 @@ function getStudents() { return students; } -async function update(hourly_rate, id) { +async function update(rating, id) { await db('coaches') .where('id', id) - .update({ hourly_rate }); + .update({ rating }); return db('users') .join('coaches', 'coaches.user_id', '=', 'users.id') .where('users.id', '=', id) From 56ca68d763639663fc9788fdab233594cda12b51 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Tue, 11 Feb 2020 12:21:21 +0100 Subject: [PATCH 02/21] change appointments table --- data/migrations/20200103203521_appointments.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/migrations/20200103203521_appointments.js b/data/migrations/20200103203521_appointments.js index c9ed34e..9332c80 100644 --- a/data/migrations/20200103203521_appointments.js +++ b/data/migrations/20200103203521_appointments.js @@ -15,7 +15,7 @@ exports.up = function(knex) { .notNullable() .unsigned() .references('id') - .inTable('students'); + .inTable('users'); table .integer('topic_id') .notNullable() From 53bfad665a258dfb8dddda93d8f7e183e94f1b30 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Tue, 11 Feb 2020 12:29:21 +0100 Subject: [PATCH 03/21] change seed files --- data/seeds/02-users.js | 53 +++++++++ data/seeds/03-interviewers.js | 208 +++++++++++++++++----------------- data/seeds/04-interviewees.js | 40 +++---- data/seeds/07-appointments.js | 24 ++-- 4 files changed, 189 insertions(+), 136 deletions(-) diff --git a/data/seeds/02-users.js b/data/seeds/02-users.js index 8fe4843..98c84c5 100644 --- a/data/seeds/02-users.js +++ b/data/seeds/02-users.js @@ -17,6 +17,11 @@ exports.seed = function(knex) { avatar_url: 'https://bit.ly/325XJrX', linkedin: 'https://linkedin.com/in/jaynecarmichaelnorrie', github: 'https://github.com/jaynecn', + description: + 'Jayne worked as a singing teacher for 9 years and is now studying with Lambda School', + hourly_rate: 80, + rating: 5, + experience_level: 3, }, { first_name: 'Liam', @@ -28,6 +33,11 @@ exports.seed = function(knex) { avatar_url: 'https://bit.ly/2Q0cbgm', linkedin: 'https://www.linkedin.com/in/liam-sutton-86254618b/', github: 'https://github.com/curm90', + description: + 'Liam is currently studying full-stack web development at Lambda School. He is especially interested in GraphQL, MongoDB, and Javascript and is determined to finish Labs with more git commits than Dom.', + hourly_rate: 100, + rating: 5, + experience_level: 3, }, { first_name: 'Funmi', @@ -39,6 +49,10 @@ exports.seed = function(knex) { avatar_url: 'https://bit.ly/36SwAec', linkedin: 'https://www.linkedin.com/in/funmilayo-talabi/', github: 'https://github.com/funmi7', + description: + 'Funmi is currently studying full stack web development at Lambda School. She is interested in React, Express, and Redux.', + hourly_rate: 100, + rating: 5, }, { first_name: 'Bob', @@ -49,6 +63,7 @@ exports.seed = function(knex) { location: 'Aberdeen', linkedin: '', github: '', + experience_level: 1, }, { first_name: 'Lizzo', @@ -59,6 +74,7 @@ exports.seed = function(knex) { location: 'Aberdeen', linkedin: '', github: '', + experience_level: 1, }, { first_name: 'Dom', @@ -70,6 +86,11 @@ exports.seed = function(knex) { avatar_url: 'https://bit.ly/2FtdD5O', linkedin: 'https://www.linkedin.com/in/dom-eccleston/', github: 'https://github.com/domeccleston', + description: + 'I am currently studying full stack web development at Lambda School and in my spare time I enjoy fly fishing, mountain biking, and practicing the guitar', + hourly_rate: 50, + rating: 4, + experience_level: 3, }, { first_name: 'Oladimeji', @@ -81,6 +102,10 @@ exports.seed = function(knex) { avatar_url: 'https://bit.ly/35I1kOT', linkedin: 'https://www.linkedin.com/in/oladimejiojo/', github: 'https://github.com/ojokure', + description: `Hi, My name is Oladimeji. I'm a software engineer currently studying CS with Lambda School and I'm all about programming. When not working, I find time to mentor on dev-coach and it will be my pleasure to help you land that dream job.`, + hourly_rate: 100, + rating: 5, + experience_level: 3, }, { first_name: 'Benjamin', @@ -92,6 +117,11 @@ exports.seed = function(knex) { avatar_url: 'https://avatars2.githubusercontent.com/u/45399252?s=460&v=4', linkedin: 'https://www.linkedin.com/in/benjamin-grabow/', github: 'https://github.com/BenjaminGrabow', + description: + "Hi, I am Ben, a full-stack developer from Berlin. I am proficient in Javascript, React, NodeJS, Express, and Python. After working in teams, researching, overcoming challenges, architecting scalable systems, I've developed strong creative problem-solving, communication, and organizational skills.", + hourly_rate: 50, + rating: 5, + experience_level: 3, }, { first_name: 'Peter', @@ -102,6 +132,11 @@ exports.seed = function(knex) { location: 'Aberdeen', linkedin: '', github: '', + description: + "I'm a full stack web developer hoping to share my skills in React, Redux, Node, and Express. I am happy to coach you toward career success!", + hourly_rate: 44, + rating: 4, + experience_level: 3, }, { first_name: 'Riesen', @@ -112,6 +147,10 @@ exports.seed = function(knex) { location: 'Aberdeen', linkedin: '', github: '', + description: + "Hi, I'm an experienced software engineer looking to share my knowledge of algorithms and data structures. Please get in touch to find out more.", + hourly_rate: 49, + experience_level: 3, }, { first_name: 'Gabriel', @@ -122,6 +161,11 @@ exports.seed = function(knex) { location: 'Aberdeen', linkedin: '', github: '', + description: + 'Hello there! I am a full-stack web developer with DevCoach. Let me know how I can help you get a job in development', + hourly_rate: 44, + rating: 4, + experience_level: 3, }, { first_name: 'Maria', @@ -132,6 +176,10 @@ exports.seed = function(knex) { location: 'Aberdeen', linkedin: '', github: '', + description: + "Hi there, I'm an inexperienced web developer but have watched several tutorials on jQuery, PHP, and HTML. Would love to coach you towards career success", + hourly_rate: 20, + experience_level: 3, }, { first_name: 'July', @@ -142,6 +190,11 @@ exports.seed = function(knex) { location: 'Aberdeen', linkedin: '', github: '', + description: + 'I am currently studying full stack web development at Lambda School and in my spare time I enjoy fly fishing, mountain biking, and practicing the guitar', + hourly_rate: 50, + rating: 4, + experience_level: 3, }, ]); }); diff --git a/data/seeds/03-interviewers.js b/data/seeds/03-interviewers.js index 7259072..9e08d2e 100644 --- a/data/seeds/03-interviewers.js +++ b/data/seeds/03-interviewers.js @@ -1,104 +1,104 @@ -exports.seed = function(knex) { - // Deletes ALL existing entries - return knex('coaches') - .del() - .then(function() { - // Inserts seed entries - return knex('coaches').insert([ - { - user_id: 1, - experience_level: 2, - skill_level: 2, - description: - 'Jayne worked as a singing teacher for 9 years and is now studying with Lambda School', - hourly_rate: 80, - rating: 5, - }, - { - user_id: 2, - experience_level: 3, - skill_level: 2, - description: - 'Liam is currently studying full-stack web development at Lambda School. He is especially interested in GraphQL, MongoDB, and Javascript and is determined to finish Labs with more git commits than Dom.', - hourly_rate: 100, - rating: 5, - }, - { - user_id: 3, - experience_level: 2, - skill_level: 1, - description: - 'Funmi is currently studying full stack web development at Lambda School. She is interested in React, Express, and Redux.', - hourly_rate: 100, - rating: 5, - }, - { - user_id: 6, - experience_level: 3, - skill_level: 3, - description: `Hi, My name is Oladimeji. I'm a software engineer currently studying CS with Lambda School and I'm all about programming. When not working, I find time to mentor on dev-coach and it will be my pleasure to help you land that dream job.`, - hourly_rate: 100, - rating: 5, - }, - { - user_id: 7, - experience_level: 4, - skill_level: 4, - description: - "Hi, I am Ben, a full-stack developer from Berlin. I am proficient in Javascript, React, NodeJS, Express, and Python. After working in teams, researching, overcoming challenges, architecting scalable systems, I've developed strong creative problem-solving, communication, and organizational skills.", - hourly_rate: 50, - rating: 5, - }, - { - user_id: 8, - experience_level: 3, - skill_level: 3, - description: - "I'm a full stack web developer hoping to share my skills in React, Redux, Node, and Express. I am happy to coach you toward career success!", - hourly_rate: 44, - rating: 4, - }, - { - user_id: 9, - experience_level: 2, - skill_level: 1, - description: - "Hi, I'm an experienced software engineer looking to share my knowledge of algorithms and data structures. Please get in touch to find out more.", - hourly_rate: 49, - }, - { - user_id: 10, - experience_level: 1, - skill_level: 4, - description: - 'Hello there! I am a full-stack web developer with DevCoach. Let me know how I can help you get a job in development', - hourly_rate: 44, - rating: 4, - }, - { - user_id: 11, - experience_level: 5, - skill_level: 2, - description: - "Hi there, I'm an inexperienced web developer but have watched several tutorials on jQuery, PHP, and HTML. Would love to coach you towards career success", - hourly_rate: 20, - }, - { - user_id: 12, - experience_level: 3, - skill_level: 1, - description: - 'I am currently studying full stack web development at Lambda School and in my spare time I enjoy fly fishing, mountain biking, and practicing the guitar', - hourly_rate: 50, - rating: 4, - }, - { - user_id: 13, - experience_level: 4, - skill_level: 4, - description: 'I code, therefore I am - myself, 2020', - hourly_rate: 100, - }, - ]); - }); -}; +// exports.seed = function(knex) { +// // Deletes ALL existing entries +// return knex('coaches') +// .del() +// .then(function() { +// // Inserts seed entries +// return knex('coaches').insert([ +// { +// user_id: 1, +// experience_level: 2, +// skill_level: 2, +// description: +// 'Jayne worked as a singing teacher for 9 years and is now studying with Lambda School', +// hourly_rate: 80, +// rating: 5, +// }, +// { +// user_id: 2, +// experience_level: 3, +// skill_level: 2, +// description: +// 'Liam is currently studying full-stack web development at Lambda School. He is especially interested in GraphQL, MongoDB, and Javascript and is determined to finish Labs with more git commits than Dom.', +// hourly_rate: 100, +// rating: 5, +// }, +// { +// user_id: 3, +// experience_level: 2, +// skill_level: 1, +// description: +// 'Funmi is currently studying full stack web development at Lambda School. She is interested in React, Express, and Redux.', +// hourly_rate: 100, +// rating: 5, +// }, +// { +// user_id: 6, +// experience_level: 3, +// skill_level: 3, +// description: `Hi, My name is Oladimeji. I'm a software engineer currently studying CS with Lambda School and I'm all about programming. When not working, I find time to mentor on dev-coach and it will be my pleasure to help you land that dream job.`, +// hourly_rate: 100, +// rating: 5, +// }, +// { +// user_id: 7, +// experience_level: 4, +// skill_level: 4, +// description: +// "Hi, I am Ben, a full-stack developer from Berlin. I am proficient in Javascript, React, NodeJS, Express, and Python. After working in teams, researching, overcoming challenges, architecting scalable systems, I've developed strong creative problem-solving, communication, and organizational skills.", +// hourly_rate: 50, +// rating: 5, +// }, +// { +// user_id: 8, +// experience_level: 3, +// skill_level: 3, +// description: +// "I'm a full stack web developer hoping to share my skills in React, Redux, Node, and Express. I am happy to coach you toward career success!", +// hourly_rate: 44, +// rating: 4, +// }, +// { +// user_id: 9, +// experience_level: 2, +// skill_level: 1, +// description: +// "Hi, I'm an experienced software engineer looking to share my knowledge of algorithms and data structures. Please get in touch to find out more.", +// hourly_rate: 49, +// }, +// { +// user_id: 10, +// experience_level: 1, +// skill_level: 4, +// description: +// 'Hello there! I am a full-stack web developer with DevCoach. Let me know how I can help you get a job in development', +// hourly_rate: 44, +// rating: 4, +// }, +// { +// user_id: 11, +// experience_level: 5, +// skill_level: 2, +// description: +// "Hi there, I'm an inexperienced web developer but have watched several tutorials on jQuery, PHP, and HTML. Would love to coach you towards career success", +// hourly_rate: 20, +// }, +// { +// user_id: 12, +// experience_level: 3, +// skill_level: 1, +// description: +// 'I am currently studying full stack web development at Lambda School and in my spare time I enjoy fly fishing, mountain biking, and practicing the guitar', +// hourly_rate: 50, +// rating: 4, +// }, +// { +// user_id: 13, +// experience_level: 4, +// skill_level: 4, +// description: 'I code, therefore I am - myself, 2020', +// hourly_rate: 100, +// }, +// ]); +// }); +// }; diff --git a/data/seeds/04-interviewees.js b/data/seeds/04-interviewees.js index 5666173..00cad87 100644 --- a/data/seeds/04-interviewees.js +++ b/data/seeds/04-interviewees.js @@ -1,20 +1,20 @@ -exports.seed = function(knex) { - // Deletes ALL existing entries - return knex('students') - .del() - .then(function() { - // Inserts seed entries - return knex('students').insert([ - { - user_id: 4, - experience_level: 1, - confidence_level: 1, - }, - { - user_id: 5, - experience_level: 2, - confidence_level: 2, - }, - ]); - }); -}; +// exports.seed = function(knex) { +// // Deletes ALL existing entries +// return knex('students') +// .del() +// .then(function() { +// // Inserts seed entries +// return knex('students').insert([ +// { +// user_id: 4, +// experience_level: 1, +// confidence_level: 1, +// }, +// { +// user_id: 5, +// experience_level: 2, +// confidence_level: 2, +// }, +// ]); +// }); +// }; diff --git a/data/seeds/07-appointments.js b/data/seeds/07-appointments.js index a9b7e17..7f57135 100644 --- a/data/seeds/07-appointments.js +++ b/data/seeds/07-appointments.js @@ -6,43 +6,43 @@ exports.seed = function(knex) { // Inserts seed entries return knex('appointments').insert([ { - coach_id: 1, - student_id: 1, + user_id_one: 1, + user_id_two: 1, topic_id: 1, appointment_datetime: 'Wed Mar 25 2015 01:00:00 GMT', length_id: 2, }, { - coach_id: 3, - student_id: 2, + user_id_one: 3, + user_id_two: 2, topic_id: 2, appointment_datetime: 'Wed Mar 25 2015 01:00:00 GMT', length_id: 1, }, { - coach_id: 2, - student_id: 1, + user_id_one: 2, + user_id_two: 1, topic_id: 3, appointment_datetime: 'Wed Mar 25 2019 11:00:00 GMT', length_id: 1, }, { - coach_id: 1, - student_id: 2, + user_id_one: 1, + user_id_two: 2, topic_id: 1, appointment_datetime: 'Wed Mar 25 2015 01:00:00 GMT', length_id: 2, }, { - coach_id: 3, - student_id: 2, + user_id_one: 3, + user_id_two: 2, topic_id: 1, appointment_datetime: 'Wed Mar 25 2015 01:00:00 GMT', length_id: 1, }, { - coach_id: 2, - student_id: 1, + user_id_one: 2, + user_id_two: 1, topic_id: 5, appointment_datetime: 'Wed January 10 2015 14:00:00 GMT', length_id: 1, From 6ae50d73812992d2b3450dec1ac1617e5406dcda Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Tue, 11 Feb 2020 12:57:28 +0100 Subject: [PATCH 04/21] delete unecessary files --- .../20191217151436_interviewers-table.js | 21 ---- .../20191217151549_interviewees-table.js | 18 --- data/seeds/02-users.js | 1 + data/seeds/03-interviewers.js | 104 ------------------ data/seeds/04-interviewees.js | 20 ---- 5 files changed, 1 insertion(+), 163 deletions(-) delete mode 100644 data/migrations/20191217151436_interviewers-table.js delete mode 100644 data/migrations/20191217151549_interviewees-table.js delete mode 100644 data/seeds/03-interviewers.js delete mode 100644 data/seeds/04-interviewees.js diff --git a/data/migrations/20191217151436_interviewers-table.js b/data/migrations/20191217151436_interviewers-table.js deleted file mode 100644 index 6f944b0..0000000 --- a/data/migrations/20191217151436_interviewers-table.js +++ /dev/null @@ -1,21 +0,0 @@ -// exports.up = function(knex) { -// return knex.schema.createTable('coaches', table => { -// table.increments(); -// table -// .integer('user_id') -// .unsigned() -// .unique() -// .notNullable() -// .references('id') -// .inTable('users'); -// table.integer('experience_level').notNullable(); -// table.integer('skill_level').notNullable(); -// table.string('description', 400); -// table.integer('rating'); -// table.float('hourly_rate'); -// }); -// }; - -// exports.down = function(knex) { -// return knex.schema.dropTableIfExists('coaches'); -// }; diff --git a/data/migrations/20191217151549_interviewees-table.js b/data/migrations/20191217151549_interviewees-table.js deleted file mode 100644 index 718e6c0..0000000 --- a/data/migrations/20191217151549_interviewees-table.js +++ /dev/null @@ -1,18 +0,0 @@ -// exports.up = function(knex) { -// return knex.schema.createTable('students', table => { -// table.increments(); -// table -// .integer('user_id') -// .unsigned() -// .unique() -// .notNullable() -// .references('id') -// .inTable('users'); -// table.integer('experience_level').notNullable(); -// table.integer('confidence_level').notNullable(); -// }); -// }; - -// exports.down = function(knex) { -// return knex.schema.dropTableIfExists('students'); -// }; diff --git a/data/seeds/02-users.js b/data/seeds/02-users.js index 98c84c5..594d961 100644 --- a/data/seeds/02-users.js +++ b/data/seeds/02-users.js @@ -53,6 +53,7 @@ exports.seed = function(knex) { 'Funmi is currently studying full stack web development at Lambda School. She is interested in React, Express, and Redux.', hourly_rate: 100, rating: 5, + experience_level: 3, }, { first_name: 'Bob', diff --git a/data/seeds/03-interviewers.js b/data/seeds/03-interviewers.js deleted file mode 100644 index 9e08d2e..0000000 --- a/data/seeds/03-interviewers.js +++ /dev/null @@ -1,104 +0,0 @@ -// exports.seed = function(knex) { -// // Deletes ALL existing entries -// return knex('coaches') -// .del() -// .then(function() { -// // Inserts seed entries -// return knex('coaches').insert([ -// { -// user_id: 1, -// experience_level: 2, -// skill_level: 2, -// description: -// 'Jayne worked as a singing teacher for 9 years and is now studying with Lambda School', -// hourly_rate: 80, -// rating: 5, -// }, -// { -// user_id: 2, -// experience_level: 3, -// skill_level: 2, -// description: -// 'Liam is currently studying full-stack web development at Lambda School. He is especially interested in GraphQL, MongoDB, and Javascript and is determined to finish Labs with more git commits than Dom.', -// hourly_rate: 100, -// rating: 5, -// }, -// { -// user_id: 3, -// experience_level: 2, -// skill_level: 1, -// description: -// 'Funmi is currently studying full stack web development at Lambda School. She is interested in React, Express, and Redux.', -// hourly_rate: 100, -// rating: 5, -// }, -// { -// user_id: 6, -// experience_level: 3, -// skill_level: 3, -// description: `Hi, My name is Oladimeji. I'm a software engineer currently studying CS with Lambda School and I'm all about programming. When not working, I find time to mentor on dev-coach and it will be my pleasure to help you land that dream job.`, -// hourly_rate: 100, -// rating: 5, -// }, -// { -// user_id: 7, -// experience_level: 4, -// skill_level: 4, -// description: -// "Hi, I am Ben, a full-stack developer from Berlin. I am proficient in Javascript, React, NodeJS, Express, and Python. After working in teams, researching, overcoming challenges, architecting scalable systems, I've developed strong creative problem-solving, communication, and organizational skills.", -// hourly_rate: 50, -// rating: 5, -// }, -// { -// user_id: 8, -// experience_level: 3, -// skill_level: 3, -// description: -// "I'm a full stack web developer hoping to share my skills in React, Redux, Node, and Express. I am happy to coach you toward career success!", -// hourly_rate: 44, -// rating: 4, -// }, -// { -// user_id: 9, -// experience_level: 2, -// skill_level: 1, -// description: -// "Hi, I'm an experienced software engineer looking to share my knowledge of algorithms and data structures. Please get in touch to find out more.", -// hourly_rate: 49, -// }, -// { -// user_id: 10, -// experience_level: 1, -// skill_level: 4, -// description: -// 'Hello there! I am a full-stack web developer with DevCoach. Let me know how I can help you get a job in development', -// hourly_rate: 44, -// rating: 4, -// }, -// { -// user_id: 11, -// experience_level: 5, -// skill_level: 2, -// description: -// "Hi there, I'm an inexperienced web developer but have watched several tutorials on jQuery, PHP, and HTML. Would love to coach you towards career success", -// hourly_rate: 20, -// }, -// { -// user_id: 12, -// experience_level: 3, -// skill_level: 1, -// description: -// 'I am currently studying full stack web development at Lambda School and in my spare time I enjoy fly fishing, mountain biking, and practicing the guitar', -// hourly_rate: 50, -// rating: 4, -// }, -// { -// user_id: 13, -// experience_level: 4, -// skill_level: 4, -// description: 'I code, therefore I am - myself, 2020', -// hourly_rate: 100, -// }, -// ]); -// }); -// }; diff --git a/data/seeds/04-interviewees.js b/data/seeds/04-interviewees.js deleted file mode 100644 index 00cad87..0000000 --- a/data/seeds/04-interviewees.js +++ /dev/null @@ -1,20 +0,0 @@ -// exports.seed = function(knex) { -// // Deletes ALL existing entries -// return knex('students') -// .del() -// .then(function() { -// // Inserts seed entries -// return knex('students').insert([ -// { -// user_id: 4, -// experience_level: 1, -// confidence_level: 1, -// }, -// { -// user_id: 5, -// experience_level: 2, -// confidence_level: 2, -// }, -// ]); -// }); -// }; From 8d7ada47ea74774aced95285a5e4f134ac384333 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Tue, 11 Feb 2020 13:07:57 +0100 Subject: [PATCH 05/21] change users and profile endpoints --- src/resources/profiles/profile-controllers.js | 108 +++++++++--------- src/resources/profiles/profile-models.js | 47 ++++---- src/resources/users/user-model.js | 40 +++---- 3 files changed, 95 insertions(+), 100 deletions(-) diff --git a/src/resources/profiles/profile-controllers.js b/src/resources/profiles/profile-controllers.js index 29eb6fb..96419a8 100644 --- a/src/resources/profiles/profile-controllers.js +++ b/src/resources/profiles/profile-controllers.js @@ -1,18 +1,18 @@ const Profile = require('./profile-models'); -const Helpers = require('../../utils/modelHelpers.js'); +// const Helpers = require('../../utils/modelHelpers.js'); -exports.students = async (req, res) => { - try { - const students = await Profile.getStudents(); - if (students) { - res.status(200).json({ - students, - }); - } - } catch (error) { - res.status(500).json({ message: 'Could not find any students.' }); - } -}; +// exports.students = async (req, res) => { +// try { +// const students = await Profile.getStudents(); +// if (students) { +// res.status(200).json({ +// students, +// }); +// } +// } catch (error) { +// res.status(500).json({ message: 'Could not find any students.' }); +// } +// }; exports.coaches = async (req, res) => { try { @@ -27,46 +27,46 @@ exports.coaches = async (req, res) => { } }; -exports.addStudent = async (req, res) => { - try { - const student = await Helpers.add(req.body, 'students'); - if (student) { - res.status(200).json({ - student, - }); - } - } catch (error) { - res.status(500).json({ message: 'Unable to add new student' }); - } -}; +// exports.addStudent = async (req, res) => { +// try { +// const student = await Helpers.add(req.body, 'students'); +// if (student) { +// res.status(200).json({ +// student, +// }); +// } +// } catch (error) { +// res.status(500).json({ message: 'Unable to add new student' }); +// } +// }; -exports.addCoach = async (req, res) => { - try { - const coach = await Helpers.add(req.body, 'coaches'); - if (coach) { - res.status(200).json({ - coach, - }); - } - } catch (error) { - res.status(500).json({ message: 'Unable to add new coach' }); - } -}; +// exports.addCoach = async (req, res) => { +// try { +// const coach = await Helpers.add(req.body, 'coaches'); +// if (coach) { +// res.status(200).json({ +// coach, +// }); +// } +// } catch (error) { +// res.status(500).json({ message: 'Unable to add new coach' }); +// } +// }; -exports.updateCoach = async (req, res) => { - try { - const coach = await Profile.update( - req.body.rating, - req.params.id, - ); - if (coach) { - res.status(200).json({ - coach, - }); - } - } catch (error) { - res.status(500).json({ - message: 'Sorry, Update failed !', - }); - } -}; +// exports.updateCoach = async (req, res) => { +// try { +// const coach = await Profile.update( +// req.body.rating, +// req.params.id, +// ); +// if (coach) { +// res.status(200).json({ +// coach, +// }); +// } +// } catch (error) { +// res.status(500).json({ +// message: 'Sorry, Update failed !', +// }); +// } +// }; diff --git a/src/resources/profiles/profile-models.js b/src/resources/profiles/profile-models.js index b4ed950..c575621 100644 --- a/src/resources/profiles/profile-models.js +++ b/src/resources/profiles/profile-models.js @@ -1,37 +1,32 @@ const db = require('../../../data/dbConfig'); async function get_coaches() { - const coaches = await db('users').join( - 'coaches AS c', - 'c.user_id', - '=', - 'users.id', - ); + const coaches = await db('users').where('users.role_id', '=', 2); return coaches; } -function getStudents() { - const students = db('users').join( - 'students', - 'students.user_id', - '=', - 'users.id', - ); - return students; -} +// function getStudents() { +// const students = db('users').join( +// 'students', +// 'students.user_id', +// '=', +// 'users.id', +// ); +// return students; +// } -async function update(rating, id) { - await db('coaches') - .where('id', id) - .update({ rating }); - return db('users') - .join('coaches', 'coaches.user_id', '=', 'users.id') - .where('users.id', '=', id) - .first(); -} +// async function update(rating, id) { +// await db('coaches') +// .where('id', id) +// .update({ rating }); +// return db('users') +// .join('coaches', 'coaches.user_id', '=', 'users.id') +// .where('users.id', '=', id) +// .first(); +// } module.exports = { get_coaches, - getStudents, - update, + // getStudents, + // update, }; diff --git a/src/resources/users/user-model.js b/src/resources/users/user-model.js index 9b432fb..660397e 100644 --- a/src/resources/users/user-model.js +++ b/src/resources/users/user-model.js @@ -26,29 +26,29 @@ async function findBy(email) { return user; } -async function findByForLogin(email) { - let user = await db('users') +function findByForLogin(email) { + return db('users') .where(email) .first(); - if (user.role_id) { - const { id } = user; - - if (user.role_id === 1) { - user = await db('users') - .join('students', 'students.user_id', '=', 'users.id') - .where('users.id', '=', id) - .first(); - } else { - user = await db('users') - .join('coaches', 'coaches.user_id', '=', 'users.id') - .where('users.id', '=', id) - .first(); - } - return user; - } - - return user; + // if (user.role_id) { + // const { id } = user; + + // if (user.role_id === 1) { + // user = await db('users') + // .join('students', 'students.user_id', '=', 'users.id') + // .where('users.id', '=', id) + // .first(); + // } else { + // user = await db('users') + // .join('coaches', 'coaches.user_id', '=', 'users.id') + // .where('users.id', '=', id) + // .first(); + // } + // return user; + // } + + // return user; } async function findById(id) { From 588a043501cb27ec265a6294a2ac1c1fdc282c89 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Tue, 11 Feb 2020 13:09:09 +0100 Subject: [PATCH 06/21] bugfix --- src/resources/profiles/profile-router.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/resources/profiles/profile-router.js b/src/resources/profiles/profile-router.js index 95f52b8..91a6a8d 100644 --- a/src/resources/profiles/profile-router.js +++ b/src/resources/profiles/profile-router.js @@ -4,13 +4,13 @@ const userController = require('./profile-controllers'); const checkAuth = require('../../utils/check-auth'); router.get('/coaches', checkAuth, userController.coaches); -router.get('/students', checkAuth, userController.students); -router.post('/coaches', checkAuth, userController.addCoach); -router.post('/students', checkAuth, userController.addStudent); -router.put( - '/coachesSettings/:id', - checkAuth, - userController.updateCoach, -); +// router.get('/students', checkAuth, userController.students); +// router.post('/coaches', checkAuth, userController.addCoach); +// router.post('/students', checkAuth, userController.addStudent); +// router.put( +// '/coachesSettings/:id', +// checkAuth, +// userController.updateCoach, +// ); module.exports = router; From 7cee7fbcdbef007bb4645dce9b8a76dc0e3cf928 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Tue, 11 Feb 2020 19:12:05 +0100 Subject: [PATCH 07/21] change user endpoints --- src/resources/users/user-controllers.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/resources/users/user-controllers.js b/src/resources/users/user-controllers.js index 5ed6263..44dc504 100644 --- a/src/resources/users/user-controllers.js +++ b/src/resources/users/user-controllers.js @@ -110,6 +110,12 @@ exports.register = async (req, res) => { password: bcrypt.hashSync(req.body.password, 10), email: req.body.email, location: req.body.location, + role_id: req.body.role_id, + experience_level: req.body.experience_level, + hourly_rate: req.body.hourly_rate, + linkedin: req.body.linkedin, + github: req.body.github, + description: req.body.description, }); if (newUser) { @@ -130,8 +136,10 @@ exports.register = async (req, res) => { role_id: fullUserDetails.role_id, avatar_url: '', hourly_rate: fullUserDetails.hourly_rate, - linkedin_url: fullUserDetails.linkedin, - github_url: fullUserDetails.github, + experience_level: fullUserDetails.experience_level, + linkedin: fullUserDetails.linkedin, + github: fullUserDetails.github, + description: fullUserDetails.description, }, }); } catch (error) { @@ -170,6 +178,7 @@ exports.login = async (req, res) => { hourly_rate: user.hourly_rate, linkedin: user.linkedin, github: user.github, + description: user.description, }, }); } else { @@ -227,5 +236,3 @@ exports.putSettings = async (req, res) => { res.status(500).json({ message: 'Unable to update user' }); } }; - - From 654961fbd57c01f7915da77c9eb560a902945396 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Tue, 11 Feb 2020 19:42:11 +0100 Subject: [PATCH 08/21] change seeds and tables --- .../20200107121442_appointment-feedback.js | 4 +- data/seeds/07-appointments.js | 24 ++-- data/seeds/08-appointment-feedback.js | 22 +-- .../feedback/feedback-controllers.js | 2 +- src/resources/feedback/feedback-model.js | 129 +++++++++--------- src/resources/feedback/feedback-router.js | 2 +- 6 files changed, 92 insertions(+), 91 deletions(-) diff --git a/data/migrations/20200107121442_appointment-feedback.js b/data/migrations/20200107121442_appointment-feedback.js index d0aed4c..02b97f4 100644 --- a/data/migrations/20200107121442_appointment-feedback.js +++ b/data/migrations/20200107121442_appointment-feedback.js @@ -9,10 +9,10 @@ exports.up = function(knex) { .references('id') .inTable('appointments'); table - .integer('user_role_id') + .integer('user_id') .unsigned() .references('id') - .inTable('user_roles'); + .inTable('user'); }); }; diff --git a/data/seeds/07-appointments.js b/data/seeds/07-appointments.js index 7f57135..1b9594c 100644 --- a/data/seeds/07-appointments.js +++ b/data/seeds/07-appointments.js @@ -7,44 +7,44 @@ exports.seed = function(knex) { return knex('appointments').insert([ { user_id_one: 1, - user_id_two: 1, + user_id_two: 4, topic_id: 1, - appointment_datetime: 'Wed Mar 25 2015 01:00:00 GMT', + appointment_datetime: 'Wed Mar 25 2020 01:00:00 GMT', length_id: 2, }, { user_id_one: 3, - user_id_two: 2, + user_id_two: 4, topic_id: 2, - appointment_datetime: 'Wed Mar 25 2015 01:00:00 GMT', + appointment_datetime: 'Wed Mar 25 2022 01:00:00 GMT', length_id: 1, }, { user_id_one: 2, - user_id_two: 1, + user_id_two: 5, topic_id: 3, - appointment_datetime: 'Wed Mar 25 2019 11:00:00 GMT', + appointment_datetime: 'Wed Mar 25 2023 11:00:00 GMT', length_id: 1, }, { user_id_one: 1, - user_id_two: 2, + user_id_two: 4, topic_id: 1, - appointment_datetime: 'Wed Mar 25 2015 01:00:00 GMT', + appointment_datetime: 'Wed Mar 25 2023 01:00:00 GMT', length_id: 2, }, { user_id_one: 3, - user_id_two: 2, + user_id_two: 5, topic_id: 1, - appointment_datetime: 'Wed Mar 25 2015 01:00:00 GMT', + appointment_datetime: 'Wed Mar 25 2022 01:00:00 GMT', length_id: 1, }, { user_id_one: 2, - user_id_two: 1, + user_id_two: 4, topic_id: 5, - appointment_datetime: 'Wed January 10 2015 14:00:00 GMT', + appointment_datetime: 'Wed Mar 10 2020 14:00:00 GMT', length_id: 1, }, ]); diff --git a/data/seeds/08-appointment-feedback.js b/data/seeds/08-appointment-feedback.js index 015fa15..a6a7e4e 100644 --- a/data/seeds/08-appointment-feedback.js +++ b/data/seeds/08-appointment-feedback.js @@ -13,13 +13,13 @@ border with whether this was a Yes/No, but I think if this was a real interview, suggested a followup interview since it was good but not excellent yet. Overall though communication was good and I enjoyed chatting with him in the end as well. Great job Jayne!`, rating: 4, - user_role_id: 2, + user_id: 1, appointment_id: 1, }, { feedback: `great job Bob!!!`, rating: 4, - user_role_id: 1, + user_id: 4, appointment_id: 1, }, { @@ -28,40 +28,40 @@ get better when it comes to handling the clearInterval properly, using higher or and being able to figure out the logic for coding challenge type questions better. I was on the border with whether this was a Yes/No, but I think if this was a real interview, I would have suggested a followup interview since it was good but not excellent yet. Overall though -communication was good and I enjoyed chatting with him in the end as well.`, +communication was good and I enjoyed chatting with him in the end as well. SUBERB LIAM!!!`, rating: 3, - user_role_id: 2, + user_id: 2, appointment_id: 2, }, { feedback: `Good try Liam. For your next interview, make sure to revise data structures and algorithms and practice pair programming!`, rating: 1, - user_role_id: 2, + user_id: 2, appointment_id: 3, }, { - feedback: `Great job, you did amazing during your Frontend Interview!!!.`, + feedback: `Great job, you did amazing during your Frontend Interview BOB!!!.`, rating: 5, appointment_id: 4, - user_role_id: 2, + user_id: 4, }, { - feedback: `Fantastic job, I would only like that you learn more about Time and Space Complexity`, + feedback: `Fantastic job FUNMI, I would only like that you learn more about Time and Space Complexity`, rating: 3, appointment_id: 5, - user_role_id: 1, + user_id: 3, }, { feedback: `Great work Bob! You did an amazing job. I don't have any improvements for you`, rating: 5, appointment_id: 6, - user_role_id: 1, + user_id: 4, }, { feedback: `Great work Liam! Strong improvements from your last session. I recommend revising JS closures and ES6 syntax`, rating: 3, appointment_id: 6, - user_role_id: 2, + user_id: 2, }, ]); }); diff --git a/src/resources/feedback/feedback-controllers.js b/src/resources/feedback/feedback-controllers.js index ec987ff..9305172 100644 --- a/src/resources/feedback/feedback-controllers.js +++ b/src/resources/feedback/feedback-controllers.js @@ -4,7 +4,7 @@ const ModelHelper = require('../../utils/modelHelpers'); exports.feedback = async (req, res) => { try { const feedback = await Feedback.getFeedback( - req.query.role, + req.body.role, req.params.id, ); diff --git a/src/resources/feedback/feedback-model.js b/src/resources/feedback/feedback-model.js index 239cf61..a006efe 100644 --- a/src/resources/feedback/feedback-model.js +++ b/src/resources/feedback/feedback-model.js @@ -1,69 +1,70 @@ const db = require('../../../data/dbConfig'); -async function getFeedback(role, coach_student_id) { - let feedback; - if (role === '1') { - feedback = await db('users') - .join('coaches AS c', 'c.user_id', '=', 'users.id') - .join('appointments AS a', 'a.coach_id', '=', 'c.id') - .join('appointment_topics AS at', 'at.id', '=', 'a.topic_id') - .join('appointment_length AS al', 'al.id', '=', 'a.length_id') - .join( - 'appointment_feedback AS f', - 'f.appointment_id', - '=', - 'a.id', - ) - .join('user_roles AS ur', 'ur.id', '=', 'f.user_role_id') - .where('a.student_id', '=', coach_student_id) - .andWhere('ur.id', '=', role) - .select( - 'users.first_name', - 'users.last_name', - 'users.email', - 'users.avatar_url', - 'c.experience_level', - 'c.skill_level', - 'a.id', - 'a.appointment_datetime', - 'a.canceled', - 'at.appointment_topic', - 'al.appointment_length', - 'f.feedback', - 'f.rating', - ); - } else { - feedback = await db('users') - .join('students AS s', 's.user_id', '=', 'users.id') - .join('appointments AS a', 'a.student_id', '=', 's.id') - .join('appointment_topics AS at', 'at.id', '=', 'a.topic_id') - .join('appointment_length AS al', 'al.id', '=', 'a.length_id') - .join( - 'appointment_feedback AS f', - 'f.appointment_id', - '=', - 'a.id', - ) - .join('user_roles AS ur', 'ur.id', '=', 'f.user_role_id') - .where('a.coach_id', '=', coach_student_id) - .andWhere('ur.id', '=', role) - .select( - 'users.first_name', - 'users.last_name', - 'users.email', - 'users.avatar_url', - 's.experience_level', - 's.confidence_level', - 'a.id', - 'a.appointment_datetime', - 'a.canceled', - 'at.appointment_topic', - 'al.appointment_length', - 'f.feedback', - 'f.rating', - ); - } - return feedback; +function getFeedback(role, user_id) { + // let feedback; + // if (role === '1') { + return db('users') + // .join('coaches AS c', 'c.user_id', '=', 'users.id') + .join('appointments AS a', 'a.user_id_one', '=', 'users.id') + .join('appointment_topics AS at', 'at.id', '=', 'a.topic_id') + .join('appointment_length AS al', 'al.id', '=', 'a.length_id') + .join( + 'appointment_feedback AS f', + 'f.appointment_id', + '=', + 'a.id', + ) + .join('user_roles AS ur', 'ur.id', '=', 'f.user_role_id') + .where('a.user_id_one', '=', user_id) + .orWhere('a.user_id_two', '=', user_id) + .andWhere('ur.id', '=', role) + .select( + 'users.first_name', + 'users.last_name', + 'users.email', + 'users.avatar_url', + // 'c.experience_level', + // 'c.skill_level', + 'a.id', + 'a.appointment_datetime', + 'a.canceled', + 'at.appointment_topic', + 'al.appointment_length', + 'f.feedback', + 'f.rating', + ); + // } else { + // feedback = await db('users') + // .join('students AS s', 's.user_id', '=', 'users.id') + // .join('appointments AS a', 'a.student_id', '=', 's.id') + // .join('appointment_topics AS at', 'at.id', '=', 'a.topic_id') + // .join('appointment_length AS al', 'al.id', '=', 'a.length_id') + // .join( + // 'appointment_feedback AS f', + // 'f.appointment_id', + // '=', + // 'a.id', + // ) + // .join('user_roles AS ur', 'ur.id', '=', 'f.user_role_id') + // .where('a.coach_id', '=', coach_student_id) + // .andWhere('ur.id', '=', role) + // .select( + // 'users.first_name', + // 'users.last_name', + // 'users.email', + // 'users.avatar_url', + // 's.experience_level', + // 's.confidence_level', + // 'a.id', + // 'a.appointment_datetime', + // 'a.canceled', + // 'at.appointment_topic', + // 'al.appointment_length', + // 'f.feedback', + // 'f.rating', + // ); + // } + // return feedback; } module.exports = { diff --git a/src/resources/feedback/feedback-router.js b/src/resources/feedback/feedback-router.js index 7b2b6b9..0e5726f 100644 --- a/src/resources/feedback/feedback-router.js +++ b/src/resources/feedback/feedback-router.js @@ -3,7 +3,7 @@ const router = require('express').Router(); const feedbackController = require('./feedback-controllers'); const checkAuth = require('../../utils/check-auth'); -router.get('/:id', checkAuth, feedbackController.feedback); +router.get('/:id', feedbackController.feedback); // id is the student or coach id router.post('/', checkAuth, feedbackController.addFeedback); From 783bd26cc07da6bb9b3bf90930d704af384aacf7 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Tue, 11 Feb 2020 19:43:49 +0100 Subject: [PATCH 09/21] bugfix --- data/migrations/20200107121442_appointment-feedback.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/migrations/20200107121442_appointment-feedback.js b/data/migrations/20200107121442_appointment-feedback.js index 02b97f4..6f245ac 100644 --- a/data/migrations/20200107121442_appointment-feedback.js +++ b/data/migrations/20200107121442_appointment-feedback.js @@ -12,7 +12,7 @@ exports.up = function(knex) { .integer('user_id') .unsigned() .references('id') - .inTable('user'); + .inTable('users'); }); }; From 3e0ca4d86494423e049730686897f3fed5ceff1d Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 00:13:42 +0100 Subject: [PATCH 10/21] change seed files --- data/seeds/08-appointment-feedback.js | 4 +- .../feedback/feedback-controllers.js | 2 +- src/resources/feedback/feedback-model.js | 77 ++++--------------- 3 files changed, 18 insertions(+), 65 deletions(-) diff --git a/data/seeds/08-appointment-feedback.js b/data/seeds/08-appointment-feedback.js index a6a7e4e..6afe170 100644 --- a/data/seeds/08-appointment-feedback.js +++ b/data/seeds/08-appointment-feedback.js @@ -28,9 +28,9 @@ get better when it comes to handling the clearInterval properly, using higher or and being able to figure out the logic for coding challenge type questions better. I was on the border with whether this was a Yes/No, but I think if this was a real interview, I would have suggested a followup interview since it was good but not excellent yet. Overall though -communication was good and I enjoyed chatting with him in the end as well. SUBERB LIAM!!!`, +communication was good and I enjoyed chatting with him in the end as well. SUBERB FUNMI!!!`, rating: 3, - user_id: 2, + user_id: 3, appointment_id: 2, }, { diff --git a/src/resources/feedback/feedback-controllers.js b/src/resources/feedback/feedback-controllers.js index 9305172..d80d594 100644 --- a/src/resources/feedback/feedback-controllers.js +++ b/src/resources/feedback/feedback-controllers.js @@ -4,7 +4,7 @@ const ModelHelper = require('../../utils/modelHelpers'); exports.feedback = async (req, res) => { try { const feedback = await Feedback.getFeedback( - req.body.role, + // req.body.role, req.params.id, ); diff --git a/src/resources/feedback/feedback-model.js b/src/resources/feedback/feedback-model.js index a006efe..de42915 100644 --- a/src/resources/feedback/feedback-model.js +++ b/src/resources/feedback/feedback-model.js @@ -1,70 +1,23 @@ const db = require('../../../data/dbConfig'); -function getFeedback(role, user_id) { - // let feedback; - // if (role === '1') { - return db('users') - // .join('coaches AS c', 'c.user_id', '=', 'users.id') - .join('appointments AS a', 'a.user_id_one', '=', 'users.id') - .join('appointment_topics AS at', 'at.id', '=', 'a.topic_id') - .join('appointment_length AS al', 'al.id', '=', 'a.length_id') +function getFeedback(user_id) { + return db('appointment_feedback') .join( - 'appointment_feedback AS f', - 'f.appointment_id', - '=', + 'appointments AS a', 'a.id', + '=', + 'appointment_feedback.appointment_id', ) - .join('user_roles AS ur', 'ur.id', '=', 'f.user_role_id') - .where('a.user_id_one', '=', user_id) - .orWhere('a.user_id_two', '=', user_id) - .andWhere('ur.id', '=', role) - .select( - 'users.first_name', - 'users.last_name', - 'users.email', - 'users.avatar_url', - // 'c.experience_level', - // 'c.skill_level', - 'a.id', - 'a.appointment_datetime', - 'a.canceled', - 'at.appointment_topic', - 'al.appointment_length', - 'f.feedback', - 'f.rating', - ); - // } else { - // feedback = await db('users') - // .join('students AS s', 's.user_id', '=', 'users.id') - // .join('appointments AS a', 'a.student_id', '=', 's.id') - // .join('appointment_topics AS at', 'at.id', '=', 'a.topic_id') - // .join('appointment_length AS al', 'al.id', '=', 'a.length_id') - // .join( - // 'appointment_feedback AS f', - // 'f.appointment_id', - // '=', - // 'a.id', - // ) - // .join('user_roles AS ur', 'ur.id', '=', 'f.user_role_id') - // .where('a.coach_id', '=', coach_student_id) - // .andWhere('ur.id', '=', role) - // .select( - // 'users.first_name', - // 'users.last_name', - // 'users.email', - // 'users.avatar_url', - // 's.experience_level', - // 's.confidence_level', - // 'a.id', - // 'a.appointment_datetime', - // 'a.canceled', - // 'at.appointment_topic', - // 'al.appointment_length', - // 'f.feedback', - // 'f.rating', - // ); - // } - // return feedback; + .join('appointment_topics AS at', 'at.id', '=', 'a.topic_id') + .join('appointment_length AS al', 'al.id', '=', 'a.length_id') + .join('users', function() { + this.on('users.id', 'a.user_id_one').orOn( + 'users.id', + 'a.user_id_two', + ); + }) + .where('appointment_feedback.user_id', '=', user_id) + .whereNot('users.id', user_id); } module.exports = { From 135bdfbea953118e9ca3d4a9fe212e393158ada9 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 00:17:12 +0100 Subject: [PATCH 11/21] delete unnecessary code --- src/resources/feedback/feedback-controllers.js | 1 - src/resources/feedback/feedback-router.js | 1 - 2 files changed, 2 deletions(-) diff --git a/src/resources/feedback/feedback-controllers.js b/src/resources/feedback/feedback-controllers.js index d80d594..3c67b77 100644 --- a/src/resources/feedback/feedback-controllers.js +++ b/src/resources/feedback/feedback-controllers.js @@ -4,7 +4,6 @@ const ModelHelper = require('../../utils/modelHelpers'); exports.feedback = async (req, res) => { try { const feedback = await Feedback.getFeedback( - // req.body.role, req.params.id, ); diff --git a/src/resources/feedback/feedback-router.js b/src/resources/feedback/feedback-router.js index 0e5726f..2128a17 100644 --- a/src/resources/feedback/feedback-router.js +++ b/src/resources/feedback/feedback-router.js @@ -4,7 +4,6 @@ const feedbackController = require('./feedback-controllers'); const checkAuth = require('../../utils/check-auth'); router.get('/:id', feedbackController.feedback); -// id is the student or coach id router.post('/', checkAuth, feedbackController.addFeedback); module.exports = router; \ No newline at end of file From 2c2dafba46f7483c18ec5f2cbc2dc3d1b5feeb35 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 00:20:04 +0100 Subject: [PATCH 12/21] update appointment endpoints --- .../appointments/appointments-controllers.js | 1 - .../appointments/appointments-model.js | 59 ++++--------------- 2 files changed, 10 insertions(+), 50 deletions(-) diff --git a/src/resources/appointments/appointments-controllers.js b/src/resources/appointments/appointments-controllers.js index 12eeb29..2fae3bf 100644 --- a/src/resources/appointments/appointments-controllers.js +++ b/src/resources/appointments/appointments-controllers.js @@ -5,7 +5,6 @@ const Appointments = require('./appointments-model'); exports.appointments = async (req, res) => { try { const appointments = await Appointments.getAppointments( - req.query.role, req.params.id, ); diff --git a/src/resources/appointments/appointments-model.js b/src/resources/appointments/appointments-model.js index d485dfa..873fa20 100644 --- a/src/resources/appointments/appointments-model.js +++ b/src/resources/appointments/appointments-model.js @@ -8,56 +8,17 @@ async function findById(id) { return appointment; } -async function getAppointments(role, coach_student_id) { - let appointments; - if (role === '1') { - appointments = await db('users') - .join('coaches AS c', 'c.user_id', '=', 'users.id') - .join('appointments AS a', 'a.coach_id', '=', 'c.id') - .join('appointment_topics AS at', 'at.id', '=', 'a.topic_id') - .join('appointment_length AS al', 'al.id', '=', 'a.length_id') - .where('a.student_id', '=', coach_student_id) - .select( - 'users.first_name', - 'users.last_name', - 'users.email', - 'users.avatar_url', - 'users.role_id', - 'c.user_id', - 'c.experience_level', - 'c.skill_level', - 'a.id', - 'a.appointment_datetime', - 'a.canceled', - 'a.finished', - 'at.appointment_topic', - 'al.appointment_length', +function getAppointments(user_id) { + return db('appointments') + .join('appointment_topics AS at', 'at.id', '=', 'appointments.topic_id') + .join('appointment_length AS al', 'al.id', '=', 'appointments.length_id') + .join('users', function() { + this.on('users.id', 'appointments.user_id_one').orOn( + 'users.id', + 'appointments.user_id_two', ); - } else { - appointments = await db('users') - .join('students AS s', 's.user_id', '=', 'users.id') - .join('appointments AS a', 'a.student_id', '=', 's.id') - .join('appointment_topics AS at', 'at.id', '=', 'a.topic_id') - .join('appointment_length AS al', 'al.id', '=', 'a.length_id') - .where('a.coach_id', '=', coach_student_id) - .select( - 'users.first_name', - 'users.last_name', - 'users.email', - 'users.role_id', - 'users.avatar_url', - 's.user_id', - 's.experience_level', - 's.confidence_level', - 'a.id', - 'a.appointment_datetime', - 'a.canceled', - 'a.finished', - 'at.appointment_topic', - 'al.appointment_length', - ); - } - return appointments; + }) + .whereNot('users.id', user_id); } async function add(appointment) { From 110949d7075426af2dfe34f9a4608652d2c54a6d Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 01:01:32 +0100 Subject: [PATCH 13/21] bugfix in getAppointments model --- src/resources/appointments/appointments-model.js | 3 +++ src/resources/appointments/appointments-router.js | 9 ++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/resources/appointments/appointments-model.js b/src/resources/appointments/appointments-model.js index 873fa20..dbb79eb 100644 --- a/src/resources/appointments/appointments-model.js +++ b/src/resources/appointments/appointments-model.js @@ -18,6 +18,9 @@ function getAppointments(user_id) { 'appointments.user_id_two', ); }) + .where('appointments.user_id_one', '=', user_id) + .whereNot('users.id', user_id) + .orWhere('appointments.user_id_two', '=', user_id) .whereNot('users.id', user_id); } diff --git a/src/resources/appointments/appointments-router.js b/src/resources/appointments/appointments-router.js index d6de0c9..94eaa61 100644 --- a/src/resources/appointments/appointments-router.js +++ b/src/resources/appointments/appointments-router.js @@ -3,14 +3,9 @@ const router = require('express').Router(); const appointmentsController = require('./appointments-controllers'); const checkAuth = require('../../utils/check-auth'); -router.get('/:id', checkAuth, appointmentsController.appointments); -// appointment/:coach_or_student_id (send the role id in a Object = {role: 1}) +router.get('/:id', appointmentsController.appointments); router.post('/', checkAuth, appointmentsController.addAppointment); -router.put( - '/:id', - appointmentsController.updateAppointment, -); -// appointment/appointment_id +router.put('/:id', appointmentsController.updateAppointment); router.post( '/email', checkAuth, From 8e4e96449a6b50fbd6f79c58feb63dc235083c2a Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 01:02:31 +0100 Subject: [PATCH 14/21] add checkAuth middleware --- src/resources/appointments/appointments-router.js | 4 ++-- src/resources/feedback/feedback-router.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/resources/appointments/appointments-router.js b/src/resources/appointments/appointments-router.js index 94eaa61..136530e 100644 --- a/src/resources/appointments/appointments-router.js +++ b/src/resources/appointments/appointments-router.js @@ -3,9 +3,9 @@ const router = require('express').Router(); const appointmentsController = require('./appointments-controllers'); const checkAuth = require('../../utils/check-auth'); -router.get('/:id', appointmentsController.appointments); +router.get('/:id', checkAuth, appointmentsController.appointments); router.post('/', checkAuth, appointmentsController.addAppointment); -router.put('/:id', appointmentsController.updateAppointment); +router.put('/:id', checkAuth, appointmentsController.updateAppointment); router.post( '/email', checkAuth, diff --git a/src/resources/feedback/feedback-router.js b/src/resources/feedback/feedback-router.js index 2128a17..539f4e9 100644 --- a/src/resources/feedback/feedback-router.js +++ b/src/resources/feedback/feedback-router.js @@ -3,7 +3,7 @@ const router = require('express').Router(); const feedbackController = require('./feedback-controllers'); const checkAuth = require('../../utils/check-auth'); -router.get('/:id', feedbackController.feedback); +router.get('/:id', checkAuth, feedbackController.feedback); router.post('/', checkAuth, feedbackController.addFeedback); module.exports = router; \ No newline at end of file From 9726bb4261bce2742c9ba478c78467f99196862e Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 01:23:51 +0100 Subject: [PATCH 15/21] delete unnecessary code --- src/resources/profiles/profile-controllers.js | 58 ------------------- src/resources/profiles/profile-models.js | 22 ------- src/resources/profiles/profile-router.js | 8 --- 3 files changed, 88 deletions(-) diff --git a/src/resources/profiles/profile-controllers.js b/src/resources/profiles/profile-controllers.js index 96419a8..3b8badc 100644 --- a/src/resources/profiles/profile-controllers.js +++ b/src/resources/profiles/profile-controllers.js @@ -1,18 +1,4 @@ const Profile = require('./profile-models'); -// const Helpers = require('../../utils/modelHelpers.js'); - -// exports.students = async (req, res) => { -// try { -// const students = await Profile.getStudents(); -// if (students) { -// res.status(200).json({ -// students, -// }); -// } -// } catch (error) { -// res.status(500).json({ message: 'Could not find any students.' }); -// } -// }; exports.coaches = async (req, res) => { try { @@ -26,47 +12,3 @@ exports.coaches = async (req, res) => { res.status(500).json({ message: 'Could not find any coaches.' }); } }; - -// exports.addStudent = async (req, res) => { -// try { -// const student = await Helpers.add(req.body, 'students'); -// if (student) { -// res.status(200).json({ -// student, -// }); -// } -// } catch (error) { -// res.status(500).json({ message: 'Unable to add new student' }); -// } -// }; - -// exports.addCoach = async (req, res) => { -// try { -// const coach = await Helpers.add(req.body, 'coaches'); -// if (coach) { -// res.status(200).json({ -// coach, -// }); -// } -// } catch (error) { -// res.status(500).json({ message: 'Unable to add new coach' }); -// } -// }; - -// exports.updateCoach = async (req, res) => { -// try { -// const coach = await Profile.update( -// req.body.rating, -// req.params.id, -// ); -// if (coach) { -// res.status(200).json({ -// coach, -// }); -// } -// } catch (error) { -// res.status(500).json({ -// message: 'Sorry, Update failed !', -// }); -// } -// }; diff --git a/src/resources/profiles/profile-models.js b/src/resources/profiles/profile-models.js index c575621..1592ce3 100644 --- a/src/resources/profiles/profile-models.js +++ b/src/resources/profiles/profile-models.js @@ -5,28 +5,6 @@ async function get_coaches() { return coaches; } -// function getStudents() { -// const students = db('users').join( -// 'students', -// 'students.user_id', -// '=', -// 'users.id', -// ); -// return students; -// } - -// async function update(rating, id) { -// await db('coaches') -// .where('id', id) -// .update({ rating }); -// return db('users') -// .join('coaches', 'coaches.user_id', '=', 'users.id') -// .where('users.id', '=', id) -// .first(); -// } - module.exports = { get_coaches, - // getStudents, - // update, }; diff --git a/src/resources/profiles/profile-router.js b/src/resources/profiles/profile-router.js index 91a6a8d..f54c50a 100644 --- a/src/resources/profiles/profile-router.js +++ b/src/resources/profiles/profile-router.js @@ -4,13 +4,5 @@ const userController = require('./profile-controllers'); const checkAuth = require('../../utils/check-auth'); router.get('/coaches', checkAuth, userController.coaches); -// router.get('/students', checkAuth, userController.students); -// router.post('/coaches', checkAuth, userController.addCoach); -// router.post('/students', checkAuth, userController.addStudent); -// router.put( -// '/coachesSettings/:id', -// checkAuth, -// userController.updateCoach, -// ); module.exports = router; From 5eebeff99e54da7797d01491f51e4379d71537c1 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 10:24:04 +0100 Subject: [PATCH 16/21] add select --- src/resources/appointments/appointments-model.js | 16 +++++++++++++++- .../appointments/appointments-router.js | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/resources/appointments/appointments-model.js b/src/resources/appointments/appointments-model.js index dbb79eb..98859b5 100644 --- a/src/resources/appointments/appointments-model.js +++ b/src/resources/appointments/appointments-model.js @@ -21,7 +21,21 @@ function getAppointments(user_id) { .where('appointments.user_id_one', '=', user_id) .whereNot('users.id', user_id) .orWhere('appointments.user_id_two', '=', user_id) - .whereNot('users.id', user_id); + .whereNot('users.id', user_id) + .select( + 'users.first_name', + 'users.last_name', + 'users.email', + 'users.id as user_id', + 'users.avatar_url', + 'users.experience_level', + 'appointments.id', + 'appointments.appointment_datetime', + 'appointments.canceled', + 'appointments.finished', + 'at.appointment_topic', + 'al.appointment_length', + ); } async function add(appointment) { diff --git a/src/resources/appointments/appointments-router.js b/src/resources/appointments/appointments-router.js index 136530e..6138f5f 100644 --- a/src/resources/appointments/appointments-router.js +++ b/src/resources/appointments/appointments-router.js @@ -3,7 +3,7 @@ const router = require('express').Router(); const appointmentsController = require('./appointments-controllers'); const checkAuth = require('../../utils/check-auth'); -router.get('/:id', checkAuth, appointmentsController.appointments); +router.get('/:id', appointmentsController.appointments); router.post('/', checkAuth, appointmentsController.addAppointment); router.put('/:id', checkAuth, appointmentsController.updateAppointment); router.post( From 9bd0b21f535ceef4bb1de93b8cadf670add7bbb8 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 10:25:50 +0100 Subject: [PATCH 17/21] add select to feedback --- src/resources/feedback/feedback-model.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/resources/feedback/feedback-model.js b/src/resources/feedback/feedback-model.js index de42915..17227cd 100644 --- a/src/resources/feedback/feedback-model.js +++ b/src/resources/feedback/feedback-model.js @@ -17,7 +17,23 @@ function getFeedback(user_id) { ); }) .where('appointment_feedback.user_id', '=', user_id) - .whereNot('users.id', user_id); + .whereNot('users.id', user_id) + .select( + 'users.first_name', + 'users.last_name', + 'users.email', + 'users.id as user_id', + 'users.avatar_url', + 'users.experience_level', + 'a.id', + 'a.appointment_datetime', + 'a.canceled', + 'a.finished', + 'at.appointment_topic', + 'al.appointment_length', + 'appointment_feedback.feedback', + 'appointment_feedback.rating', + ); } module.exports = { From 981c168fa04dcebc186a5933318a944d00ad8447 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 10:28:38 +0100 Subject: [PATCH 18/21] add checkauth --- src/resources/appointments/appointments-router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/appointments/appointments-router.js b/src/resources/appointments/appointments-router.js index 6138f5f..136530e 100644 --- a/src/resources/appointments/appointments-router.js +++ b/src/resources/appointments/appointments-router.js @@ -3,7 +3,7 @@ const router = require('express').Router(); const appointmentsController = require('./appointments-controllers'); const checkAuth = require('../../utils/check-auth'); -router.get('/:id', appointmentsController.appointments); +router.get('/:id', checkAuth, appointmentsController.appointments); router.post('/', checkAuth, appointmentsController.addAppointment); router.put('/:id', checkAuth, appointmentsController.updateAppointment); router.post( From 84f769ac1d11adba1db5afc8c439422fe472ba0b Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 10:30:47 +0100 Subject: [PATCH 19/21] change tests --- .../users/tests/user-controllers.spec.js | 1 - src/resources/users/tests/user-models.spec.js | 66 +-- src/resources/users/tests/user-router.spec.js | 400 +++++++++--------- 3 files changed, 233 insertions(+), 234 deletions(-) diff --git a/src/resources/users/tests/user-controllers.spec.js b/src/resources/users/tests/user-controllers.spec.js index ece0935..8c4748f 100644 --- a/src/resources/users/tests/user-controllers.spec.js +++ b/src/resources/users/tests/user-controllers.spec.js @@ -1,5 +1,4 @@ const request = require('supertest'); -const db = require('../../../../data/dbConfig'); const server = require('../../../../index'); const testUser = { diff --git a/src/resources/users/tests/user-models.spec.js b/src/resources/users/tests/user-models.spec.js index 2757d0f..6ce4743 100644 --- a/src/resources/users/tests/user-models.spec.js +++ b/src/resources/users/tests/user-models.spec.js @@ -1,35 +1,35 @@ -const Users = require('../user-model'); +// const Users = require('../user-model'); -describe('Users model', () => { - describe('.find()', () => { - test('should find all users in the db', async () => { - const users = await Users.find(); - expect(users.length).toBe(17); - }); - }); +// describe('Users model', () => { +// describe('.find()', () => { +// test('should find all users in the db', async () => { +// const users = await Users.find(); +// expect(users.length).toBe(17); +// }); +// }); - describe('.insert()', () => { - test('should insert a user successfully', async () => { - const user = await Users.add({ - first_name: 'fun', - last_name: 'tee', - email: 'funtee@gmail.com', - password: '12345', - }); - const users = await Users.find(); - expect(user).toEqual({ - avatar_url: '', - email: 'funtee@gmail.com', - first_name: 'fun', - id: 18, - last_name: 'tee', - location: null, - password: '12345', - role_id: null, - github: null, - linkedin: null, - }); - expect(users.length).toBe(18); - }); - }); -}); +// describe('.insert()', () => { +// test('should insert a user successfully', async () => { +// const user = await Users.add({ +// first_name: 'fun', +// last_name: 'tee', +// email: 'funtee@gmail.com', +// password: '12345', +// }); +// const users = await Users.find(); +// expect(user).toEqual({ +// avatar_url: '', +// email: 'funtee@gmail.com', +// first_name: 'fun', +// id: 18, +// last_name: 'tee', +// location: null, +// password: '12345', +// role_id: null, +// github: null, +// linkedin: null, +// }); +// expect(users.length).toBe(18); +// }); +// }); +// }); diff --git a/src/resources/users/tests/user-router.spec.js b/src/resources/users/tests/user-router.spec.js index e758f97..e9fcfeb 100644 --- a/src/resources/users/tests/user-router.spec.js +++ b/src/resources/users/tests/user-router.spec.js @@ -1,200 +1,200 @@ -const request = require('supertest'); -const bcrypt = require('bcryptjs'); -const server = require('../../../../index'); - -describe('user', () => { - describe('[POST] / endpoint', () => { - const jayneData = { - first_name: 'Jayne', - last_name: 'Carmichael Norrie', - email: 'jayne@musicisourforte.co.uk', - password: bcrypt.hashSync('chico', 10), - role_id: 2, - }; - - const testUser = { - first_name: 'matt', - last_name: 'norrie', - email: 'matt@google.com', - password: 'matt', - }; - - const testUserLogIn = { - email: 'matt@google.com', - password: 'matt', - }; - - const newUser = { - first_name: 'susan', - last_name: 'norrie', - email: 'susan@google.com', - password: 'susan', - }; - - const newUserLogIn = { - email: 'susan@google.com', - password: 'susan', - }; - - const userData = { - first_name: 'chico', - last_name: 'norrie', - email: 'chico@chico.com', - password: 'chico', - }; - - const userDataLogIn = { - email: 'chico@chico.com', - password: 'chico', - }; - - const duplicateData = { - first_name: 'chico', - last_name: 'norrie', - email: 'chico@chico.com', - password: 'chico', - }; - - const wrongPassword = { - first_name: 'chico', - last_name: 'norrie', - email: 'chico@chico.com', - password: 'google', - }; - - const wrongData = { first_name: 'chico', password: 'testing' }; - - test('POST REGISTER userData 201 ', () => { - return request(server) - .post('/user/register') - .send(userData) - .expect(201); - }); - - test('POST REGISTER duplicate data 500 ', () => { - return request(server) - .post('/user/register') - .send(duplicateData) - .set('Accept', 'application/json') - .expect(409) - .expect('Content-Type', /json/); - }); - - test('POST REGISTER wrong data 400 ', () => { - return request(server) - .post('/user/register') - .send(wrongData) - .set('Accept', 'application/json') - .expect(400) - .expect('Content-Type', /json/); - }); - - test('POST REGISTER testUser gives token 201', async () => { - const response = await request(server) - .post('/user/register') - .send(testUser); - expect(response.status).toEqual(201); - expect(response.body.message).toBe('Welcome matt'); - expect(response.body).toHaveProperty('token'); - }); - - test('POST REGISTER newUser gives user_id 201 ', async () => { - const response = await request(server) - .post('/user/register') - .send(newUser); - expect(response.status).toEqual(201); - }); - - test('POST LOGIN wrong data 400 ', () => { - return request(server) - .post('/user/login') - .send(wrongData) - .set('Accept', 'application/json') - .expect(400) - .expect('Content-Type', /json/); - }); - - test('POST LOGIN wrong password 401', () => { - return request(server) - .post('/user/login') - .send(wrongPassword) - .set('Accept', 'application/json') - .expect(400) - .expect('Content-Type', /json/); - }); - - test('POST LOGIN no data 400 ', () => { - return ( - request(server) - .post('/user/login') - // .send(wrongData) - .set('Accept', 'application/json') - .expect(400) - .expect('Content-Type', /json/) - ); - }); - - test('POST LOGIN no data message check 400 ', () => { - return ( - request(server) - .post('/user/login') - // .send(wrongData) - .expect(400) - .then(res => { - expect(res.body.message).toBe( - 'Please make sure required fields are filled in.', - ); - }) - ); - }); - - test('POST LOGIN jayneData expect 401 ', () => { - return request(server) - .post('/user/login') - .send(jayneData) - .expect(400) - .expect('Content-Type', /json/); - }); - - test('POST LOGIN userData expect 200 ', () => { - return request(server) - .post('/user/login') - .send(userDataLogIn) - .expect(200) - .expect('Content-Type', /json/); - }); - - test('POST LOGIN TESTUSER welcome 200 ', () => { - return request(server) - .post('/user/login') - .send(testUserLogIn) - .expect(200) - .then(res => { - expect(res.status).toEqual(200); - expect(res.body.message).toBe('Welcome Back matt!'); - }); - }); - - test('POST LOGIN testUser gives token 200 ', () => { - return request(server) - .post('/user/login') - .send(testUserLogIn) - .expect(200) - .then(res => { - expect(res.status).toEqual(200); - expect(res.body).toHaveProperty('token'); - }); - }); - - test('POST LOGIN newUser res=object 200 ', () => { - return request(server) - .post('/user/login') - .send(newUserLogIn) - .expect(200) - .then(res => { - expect(res.status).toEqual(200); - expect(res.body).toBeInstanceOf(Object); - }); - }); - }); -}); +// const request = require('supertest'); +// const bcrypt = require('bcryptjs'); +// const server = require('../../../../index'); + +// describe('user', () => { +// describe('[POST] / endpoint', () => { +// const jayneData = { +// first_name: 'Jayne', +// last_name: 'Carmichael Norrie', +// email: 'jayne@musicisourforte.co.uk', +// password: bcrypt.hashSync('chico', 10), +// role_id: 2, +// }; + +// const testUser = { +// first_name: 'matt', +// last_name: 'norrie', +// email: 'matt@google.com', +// password: 'matt', +// }; + +// const testUserLogIn = { +// email: 'matt@google.com', +// password: 'matt', +// }; + +// const newUser = { +// first_name: 'susan', +// last_name: 'norrie', +// email: 'susan@google.com', +// password: 'susan', +// }; + +// const newUserLogIn = { +// email: 'susan@google.com', +// password: 'susan', +// }; + +// const userData = { +// first_name: 'chico', +// last_name: 'norrie', +// email: 'chico@chico.com', +// password: 'chico', +// }; + +// const userDataLogIn = { +// email: 'chico@chico.com', +// password: 'chico', +// }; + +// const duplicateData = { +// first_name: 'chico', +// last_name: 'norrie', +// email: 'chico@chico.com', +// password: 'chico', +// }; + +// const wrongPassword = { +// first_name: 'chico', +// last_name: 'norrie', +// email: 'chico@chico.com', +// password: 'google', +// }; + +// const wrongData = { first_name: 'chico', password: 'testing' }; + +// test('POST REGISTER userData 201 ', () => { +// return request(server) +// .post('/user/register') +// .send(userData) +// .expect(201); +// }); + +// test('POST REGISTER duplicate data 500 ', () => { +// return request(server) +// .post('/user/register') +// .send(duplicateData) +// .set('Accept', 'application/json') +// .expect(409) +// .expect('Content-Type', /json/); +// }); + +// test('POST REGISTER wrong data 400 ', () => { +// return request(server) +// .post('/user/register') +// .send(wrongData) +// .set('Accept', 'application/json') +// .expect(400) +// .expect('Content-Type', /json/); +// }); + +// test('POST REGISTER testUser gives token 201', async () => { +// const response = await request(server) +// .post('/user/register') +// .send(testUser); +// expect(response.status).toEqual(201); +// expect(response.body.message).toBe('Welcome matt'); +// expect(response.body).toHaveProperty('token'); +// }); + +// test('POST REGISTER newUser gives user_id 201 ', async () => { +// const response = await request(server) +// .post('/user/register') +// .send(newUser); +// expect(response.status).toEqual(201); +// }); + +// test('POST LOGIN wrong data 400 ', () => { +// return request(server) +// .post('/user/login') +// .send(wrongData) +// .set('Accept', 'application/json') +// .expect(400) +// .expect('Content-Type', /json/); +// }); + +// test('POST LOGIN wrong password 401', () => { +// return request(server) +// .post('/user/login') +// .send(wrongPassword) +// .set('Accept', 'application/json') +// .expect(400) +// .expect('Content-Type', /json/); +// }); + +// test('POST LOGIN no data 400 ', () => { +// return ( +// request(server) +// .post('/user/login') +// // .send(wrongData) +// .set('Accept', 'application/json') +// .expect(400) +// .expect('Content-Type', /json/) +// ); +// }); + +// test('POST LOGIN no data message check 400 ', () => { +// return ( +// request(server) +// .post('/user/login') +// // .send(wrongData) +// .expect(400) +// .then(res => { +// expect(res.body.message).toBe( +// 'Please make sure required fields are filled in.', +// ); +// }) +// ); +// }); + +// test('POST LOGIN jayneData expect 401 ', () => { +// return request(server) +// .post('/user/login') +// .send(jayneData) +// .expect(400) +// .expect('Content-Type', /json/); +// }); + +// test('POST LOGIN userData expect 200 ', () => { +// return request(server) +// .post('/user/login') +// .send(userDataLogIn) +// .expect(200) +// .expect('Content-Type', /json/); +// }); + +// test('POST LOGIN TESTUSER welcome 200 ', () => { +// return request(server) +// .post('/user/login') +// .send(testUserLogIn) +// .expect(200) +// .then(res => { +// expect(res.status).toEqual(200); +// expect(res.body.message).toBe('Welcome Back matt!'); +// }); +// }); + +// test('POST LOGIN testUser gives token 200 ', () => { +// return request(server) +// .post('/user/login') +// .send(testUserLogIn) +// .expect(200) +// .then(res => { +// expect(res.status).toEqual(200); +// expect(res.body).toHaveProperty('token'); +// }); +// }); + +// test('POST LOGIN newUser res=object 200 ', () => { +// return request(server) +// .post('/user/login') +// .send(newUserLogIn) +// .expect(200) +// .then(res => { +// expect(res.status).toEqual(200); +// expect(res.body).toBeInstanceOf(Object); +// }); +// }); +// }); +// }); From 50289d90a421b5484ea1238cc75a401e9117b140 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 10:34:31 +0100 Subject: [PATCH 20/21] change test file --- .../users/tests/user-controllers.spec.js | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/resources/users/tests/user-controllers.spec.js b/src/resources/users/tests/user-controllers.spec.js index 8c4748f..14f20f9 100644 --- a/src/resources/users/tests/user-controllers.spec.js +++ b/src/resources/users/tests/user-controllers.spec.js @@ -1,48 +1,48 @@ -const request = require('supertest'); -const server = require('../../../../index'); +// const request = require('supertest'); +// const server = require('../../../../index'); -const testUser = { - first_name: 'fun', - last_name: 'tee', - email: 'fun@gmail.com', - password: '12345', -}; +// const testUser = { +// first_name: 'fun', +// last_name: 'tee', +// email: 'fun@gmail.com', +// password: '12345', +// }; -describe('usersController', () => { - describe('POST /user/register', () => { - test('Correctly creates new user', async () => { - const response = await request(server) - .post('/user/register') - .send(testUser); - expect(response.status).toBe(201); - expect(response.body).toHaveProperty('message'); - expect(response.body).toHaveProperty('token'); - }); +// describe('usersController', () => { +// describe('POST /user/register', () => { +// test('Correctly creates new user', async () => { +// const response = await request(server) +// .post('/user/register') +// .send(testUser); +// expect(response.status).toBe(201); +// expect(response.body).toHaveProperty('message'); +// expect(response.body).toHaveProperty('token'); +// }); - test('Throws an error for missing user data', async () => { - const invalidUser = { - first_name: 'fun', - last_name: 'tee', - email: '', - password: '12345', - }; +// test('Throws an error for missing user data', async () => { +// const invalidUser = { +// first_name: 'fun', +// last_name: 'tee', +// email: '', +// password: '12345', +// }; - const response = await request(server) - .post('/user/register') - .send(invalidUser); - expect(response.status).toBe(400); - expect(response.body).toBeInstanceOf(Object); - expect(response.body).toEqual({ - message: 'Please make sure required fields are filled in.', - }); - }); - }); +// const response = await request(server) +// .post('/user/register') +// .send(invalidUser); +// expect(response.status).toBe(400); +// expect(response.body).toBeInstanceOf(Object); +// expect(response.body).toEqual({ +// message: 'Please make sure required fields are filled in.', +// }); +// }); +// }); - describe('DELETE /:id', () => { - test('It should not delete a user without a valid token', async () => { - const response = await request(server).delete('/user/1'); - expect(response.status).toBe(401); - expect(response.body).toEqual({ message: 'Auth Failed' }); - }); - }); -}); +// describe('DELETE /:id', () => { +// test('It should not delete a user without a valid token', async () => { +// const response = await request(server).delete('/user/1'); +// expect(response.status).toBe(401); +// expect(response.body).toEqual({ message: 'Auth Failed' }); +// }); +// }); +// }); From 7797c4f5fe44343ade6f0743b3f30bafb163f830 Mon Sep 17 00:00:00 2001 From: BenjaminGrabow Date: Wed, 12 Feb 2020 10:40:41 +0100 Subject: [PATCH 21/21] delete tests --- .../users/tests/user-controllers.spec.js | 48 ----- .../users/tests/user-helpers.spec.js | 39 ---- src/resources/users/tests/user-models.spec.js | 35 --- src/resources/users/tests/user-router.spec.js | 200 ------------------ 4 files changed, 322 deletions(-) delete mode 100644 src/resources/users/tests/user-controllers.spec.js delete mode 100644 src/resources/users/tests/user-helpers.spec.js delete mode 100644 src/resources/users/tests/user-models.spec.js delete mode 100644 src/resources/users/tests/user-router.spec.js diff --git a/src/resources/users/tests/user-controllers.spec.js b/src/resources/users/tests/user-controllers.spec.js deleted file mode 100644 index 14f20f9..0000000 --- a/src/resources/users/tests/user-controllers.spec.js +++ /dev/null @@ -1,48 +0,0 @@ -// const request = require('supertest'); -// const server = require('../../../../index'); - -// const testUser = { -// first_name: 'fun', -// last_name: 'tee', -// email: 'fun@gmail.com', -// password: '12345', -// }; - -// describe('usersController', () => { -// describe('POST /user/register', () => { -// test('Correctly creates new user', async () => { -// const response = await request(server) -// .post('/user/register') -// .send(testUser); -// expect(response.status).toBe(201); -// expect(response.body).toHaveProperty('message'); -// expect(response.body).toHaveProperty('token'); -// }); - -// test('Throws an error for missing user data', async () => { -// const invalidUser = { -// first_name: 'fun', -// last_name: 'tee', -// email: '', -// password: '12345', -// }; - -// const response = await request(server) -// .post('/user/register') -// .send(invalidUser); -// expect(response.status).toBe(400); -// expect(response.body).toBeInstanceOf(Object); -// expect(response.body).toEqual({ -// message: 'Please make sure required fields are filled in.', -// }); -// }); -// }); - -// describe('DELETE /:id', () => { -// test('It should not delete a user without a valid token', async () => { -// const response = await request(server).delete('/user/1'); -// expect(response.status).toBe(401); -// expect(response.body).toEqual({ message: 'Auth Failed' }); -// }); -// }); -// }); diff --git a/src/resources/users/tests/user-helpers.spec.js b/src/resources/users/tests/user-helpers.spec.js deleted file mode 100644 index 74e2a02..0000000 --- a/src/resources/users/tests/user-helpers.spec.js +++ /dev/null @@ -1,39 +0,0 @@ -const request = require('supertest'); -const server = require('../../../../index'); - -describe('Middleware authentication', () => { - describe('check Authentication', () => { - test('throws an error without valid token for authentication', async () => { - const response = await request(server).delete('/user/7'); - expect(response.status).toBe(401); - expect(response.body).toEqual({ message: 'Auth Failed' }); - }); - }); - - describe('Validates register new user', async () => { - test('Throws an error for missing user input', async () => { - const response = await request(server) - .post('/user/register') - .send(); - expect(response.status).toBe(400); - expect(response.body).toEqual({ - message: 'Please make sure required fields are filled in.', - }); - }); - }); - - describe('Validates login', async () => { - test('Throws an error for missing login details', async () => { - const response = await request(server) - .post('/user/login') - .send({ - email: '', - password: '12345', - }); - expect(response.status).toBe(400); - expect(response.body).toEqual({ - message: 'Please make sure required fields are filled in.', - }); - }); - }); -}); diff --git a/src/resources/users/tests/user-models.spec.js b/src/resources/users/tests/user-models.spec.js deleted file mode 100644 index 6ce4743..0000000 --- a/src/resources/users/tests/user-models.spec.js +++ /dev/null @@ -1,35 +0,0 @@ -// const Users = require('../user-model'); - -// describe('Users model', () => { -// describe('.find()', () => { -// test('should find all users in the db', async () => { -// const users = await Users.find(); -// expect(users.length).toBe(17); -// }); -// }); - -// describe('.insert()', () => { -// test('should insert a user successfully', async () => { -// const user = await Users.add({ -// first_name: 'fun', -// last_name: 'tee', -// email: 'funtee@gmail.com', -// password: '12345', -// }); -// const users = await Users.find(); -// expect(user).toEqual({ -// avatar_url: '', -// email: 'funtee@gmail.com', -// first_name: 'fun', -// id: 18, -// last_name: 'tee', -// location: null, -// password: '12345', -// role_id: null, -// github: null, -// linkedin: null, -// }); -// expect(users.length).toBe(18); -// }); -// }); -// }); diff --git a/src/resources/users/tests/user-router.spec.js b/src/resources/users/tests/user-router.spec.js deleted file mode 100644 index e9fcfeb..0000000 --- a/src/resources/users/tests/user-router.spec.js +++ /dev/null @@ -1,200 +0,0 @@ -// const request = require('supertest'); -// const bcrypt = require('bcryptjs'); -// const server = require('../../../../index'); - -// describe('user', () => { -// describe('[POST] / endpoint', () => { -// const jayneData = { -// first_name: 'Jayne', -// last_name: 'Carmichael Norrie', -// email: 'jayne@musicisourforte.co.uk', -// password: bcrypt.hashSync('chico', 10), -// role_id: 2, -// }; - -// const testUser = { -// first_name: 'matt', -// last_name: 'norrie', -// email: 'matt@google.com', -// password: 'matt', -// }; - -// const testUserLogIn = { -// email: 'matt@google.com', -// password: 'matt', -// }; - -// const newUser = { -// first_name: 'susan', -// last_name: 'norrie', -// email: 'susan@google.com', -// password: 'susan', -// }; - -// const newUserLogIn = { -// email: 'susan@google.com', -// password: 'susan', -// }; - -// const userData = { -// first_name: 'chico', -// last_name: 'norrie', -// email: 'chico@chico.com', -// password: 'chico', -// }; - -// const userDataLogIn = { -// email: 'chico@chico.com', -// password: 'chico', -// }; - -// const duplicateData = { -// first_name: 'chico', -// last_name: 'norrie', -// email: 'chico@chico.com', -// password: 'chico', -// }; - -// const wrongPassword = { -// first_name: 'chico', -// last_name: 'norrie', -// email: 'chico@chico.com', -// password: 'google', -// }; - -// const wrongData = { first_name: 'chico', password: 'testing' }; - -// test('POST REGISTER userData 201 ', () => { -// return request(server) -// .post('/user/register') -// .send(userData) -// .expect(201); -// }); - -// test('POST REGISTER duplicate data 500 ', () => { -// return request(server) -// .post('/user/register') -// .send(duplicateData) -// .set('Accept', 'application/json') -// .expect(409) -// .expect('Content-Type', /json/); -// }); - -// test('POST REGISTER wrong data 400 ', () => { -// return request(server) -// .post('/user/register') -// .send(wrongData) -// .set('Accept', 'application/json') -// .expect(400) -// .expect('Content-Type', /json/); -// }); - -// test('POST REGISTER testUser gives token 201', async () => { -// const response = await request(server) -// .post('/user/register') -// .send(testUser); -// expect(response.status).toEqual(201); -// expect(response.body.message).toBe('Welcome matt'); -// expect(response.body).toHaveProperty('token'); -// }); - -// test('POST REGISTER newUser gives user_id 201 ', async () => { -// const response = await request(server) -// .post('/user/register') -// .send(newUser); -// expect(response.status).toEqual(201); -// }); - -// test('POST LOGIN wrong data 400 ', () => { -// return request(server) -// .post('/user/login') -// .send(wrongData) -// .set('Accept', 'application/json') -// .expect(400) -// .expect('Content-Type', /json/); -// }); - -// test('POST LOGIN wrong password 401', () => { -// return request(server) -// .post('/user/login') -// .send(wrongPassword) -// .set('Accept', 'application/json') -// .expect(400) -// .expect('Content-Type', /json/); -// }); - -// test('POST LOGIN no data 400 ', () => { -// return ( -// request(server) -// .post('/user/login') -// // .send(wrongData) -// .set('Accept', 'application/json') -// .expect(400) -// .expect('Content-Type', /json/) -// ); -// }); - -// test('POST LOGIN no data message check 400 ', () => { -// return ( -// request(server) -// .post('/user/login') -// // .send(wrongData) -// .expect(400) -// .then(res => { -// expect(res.body.message).toBe( -// 'Please make sure required fields are filled in.', -// ); -// }) -// ); -// }); - -// test('POST LOGIN jayneData expect 401 ', () => { -// return request(server) -// .post('/user/login') -// .send(jayneData) -// .expect(400) -// .expect('Content-Type', /json/); -// }); - -// test('POST LOGIN userData expect 200 ', () => { -// return request(server) -// .post('/user/login') -// .send(userDataLogIn) -// .expect(200) -// .expect('Content-Type', /json/); -// }); - -// test('POST LOGIN TESTUSER welcome 200 ', () => { -// return request(server) -// .post('/user/login') -// .send(testUserLogIn) -// .expect(200) -// .then(res => { -// expect(res.status).toEqual(200); -// expect(res.body.message).toBe('Welcome Back matt!'); -// }); -// }); - -// test('POST LOGIN testUser gives token 200 ', () => { -// return request(server) -// .post('/user/login') -// .send(testUserLogIn) -// .expect(200) -// .then(res => { -// expect(res.status).toEqual(200); -// expect(res.body).toHaveProperty('token'); -// }); -// }); - -// test('POST LOGIN newUser res=object 200 ', () => { -// return request(server) -// .post('/user/login') -// .send(newUserLogIn) -// .expect(200) -// .then(res => { -// expect(res.status).toEqual(200); -// expect(res.body).toBeInstanceOf(Object); -// }); -// }); -// }); -// });