From 74b24ba9fac215dc202eb2f308507401a59d3b73 Mon Sep 17 00:00:00 2001 From: Erik Sandoval Date: Sun, 8 Sep 2019 19:56:52 -0700 Subject: [PATCH 1/6] format and package upgrade --- .../20190724190911_users_reviews.js | 35 ++++++++----------- .../20190726130856_update_items_tbl.js | 24 ++++++------- data/seeds/003_users_reviews.js | 31 ++++++++-------- package-lock.json | 6 ++-- package.json | 2 +- routes/items/itemsModel.js | 24 +++++++------ routes/items/itemsRouter.js | 10 +++--- routes/users/usersModel.js | 1 - 8 files changed, 65 insertions(+), 68 deletions(-) diff --git a/data/migrations/20190724190911_users_reviews.js b/data/migrations/20190724190911_users_reviews.js index 77fcddb..ff06801 100644 --- a/data/migrations/20190724190911_users_reviews.js +++ b/data/migrations/20190724190911_users_reviews.js @@ -1,28 +1,23 @@ - exports.up = function(knex) { - return knex.schema.createTable('users_reviews', tbl => { - tbl - .increments(); + return knex.schema.createTable('users_reviews', tbl => { + tbl.increments(); + + tbl + .integer('user_id', 255) + .references('id') + .inTable('users') + .notNull(); + + tbl.integer('reviewer_id', 255).notNull(); - tbl - .integer('user_id', 255) - .references('id').inTable('users').notNull(); + tbl.decimal('rating', 8, 2); - tbl - .integer('reviewer_id', 255) - .notNull(); + tbl.string('review_title', 255); - tbl - .decimal('rating', 8, 2); - - tbl - .string('review_title', 255); - - tbl - .string('review_body', 255); - }) + tbl.string('review_body', 255); + }); }; exports.down = function(knex) { - return knex.schema.dropTableIfExists('users_reviews'); + return knex.schema.dropTableIfExists('users_reviews'); }; diff --git a/data/migrations/20190726130856_update_items_tbl.js b/data/migrations/20190726130856_update_items_tbl.js index 9d16deb..98f5b50 100644 --- a/data/migrations/20190726130856_update_items_tbl.js +++ b/data/migrations/20190726130856_update_items_tbl.js @@ -1,17 +1,15 @@ - exports.up = function(knex) { - return knex.schema.table('items', function(tbl) { - - tbl.string('condition', 128); - tbl.string('sub_category', 50); - tbl.string('city', 255); - tbl.string('state', 255); - tbl.string('zipcode', 12); - }); + return knex.schema.table('items', function(tbl) { + tbl.string('condition', 128); + tbl.string('sub_category', 50); + tbl.string('city', 255); + tbl.string('state', 255); + tbl.string('zipcode', 12); + }); }; exports.down = function(knex) { - return knex.schema.table('items', function(tbl) { - tbl.dropColumns('city', 'state', 'zipcode', 'condition', 'sub_category'); -}); -} \ No newline at end of file + return knex.schema.table('items', function(tbl) { + tbl.dropColumns('city', 'state', 'zipcode', 'condition', 'sub_category'); + }); +}; diff --git a/data/seeds/003_users_reviews.js b/data/seeds/003_users_reviews.js index 3a162c1..e931967 100644 --- a/data/seeds/003_users_reviews.js +++ b/data/seeds/003_users_reviews.js @@ -1,49 +1,52 @@ - exports.seed = function(knex) { // Deletes ALL existing entries return knex('users_reviews') .truncate() - .then(function () { + .then(function() { // Inserts seed entries return knex('users_reviews').insert([ { user_id: 1, reviewer_id: 2, rating: 4.5, - review_title: "Great Job", - review_body: "Love this user so much! Excellent work and great service. Always rent things from him" - + review_title: 'Great Job', + review_body: + 'Love this user so much! Excellent work and great service. Always rent things from him', }, { user_id: 1, reviewer_id: 3, rating: 4.0, - review_title: "Very Good", - review_body: "Love this user so much! Excellent work and great service. Always rent things from him" + review_title: 'Very Good', + review_body: + 'Love this user so much! Excellent work and great service. Always rent things from him', }, { user_id: 1, reviewer_id: 3, rating: 5.0, - review_title: "Amazing", - review_body: "Love this user so much! Excellent work and great service. Always rent things from him" + review_title: 'Amazing', + review_body: + 'Love this user so much! Excellent work and great service. Always rent things from him', }, { user_id: 2, reviewer_id: 3, rating: 5.0, - review_title: "Amazing", - review_body: "Love this user so much! Excellent work and great service. Always rent things from him" + review_title: 'Amazing', + review_body: + 'Love this user so much! Excellent work and great service. Always rent things from him', }, { user_id: 2, reviewer_id: 3, rating: 5.0, - review_title: "Amazing", - review_body: "Love this user so much! Excellent work and great service. Always rent things from him" - } + review_title: 'Amazing', + review_body: + 'Love this user so much! Excellent work and great service. Always rent things from him', + }, ]); }); }; diff --git a/package-lock.json b/package-lock.json index cf04954..487fdc0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4500,9 +4500,9 @@ } }, "eslint-utils": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.0.tgz", - "integrity": "sha512-7ehnzPaP5IIEh1r1tkjuIrxqhNkzUJa9z3R92tLJdZIVdWaczEhr3EbhGtsMrVxi1KeR8qA7Off6SWc5WNQqyQ==", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.2.tgz", + "integrity": "sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q==", "dev": true, "requires": { "eslint-visitor-keys": "^1.0.0" diff --git a/package.json b/package.json index 77db9a2..e637739 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "helmet": "^3.18.0", "heroku-cli": "^7.0.9", "jsonwebtoken": "^8.5.1", - "knex": "^0.18.3", + "knex": "^0.18.4", "passport": "^0.4.0", "passport-google-oauth20": "^2.0.0", "pg": "^7.11.0", diff --git a/routes/items/itemsModel.js b/routes/items/itemsModel.js index ca6136d..22a7b54 100644 --- a/routes/items/itemsModel.js +++ b/routes/items/itemsModel.js @@ -2,25 +2,29 @@ const knex = require('knex'); const db = require('../../data/dbConfig'); module.exports = { - getAll, - getItemById, - updateItem, - deleteItem -} + getAll, + getItemById, + updateItem, + deleteItem, +}; function getAll() { - return db('items'); + return db('items'); } function getItemById(id) { - return db('items').where({id}).first(); + return db('items') + .where({ id }) + .first(); } async function updateItem(id, updatedItem) { - const updated = await getItemById(id).update(updatedItem); - return updated; + const updated = await getItemById(id).update(updatedItem); + return updated; } function deleteItem(id) { - return db('items').where({id}).delete(); + return db('items') + .where({ id }) + .delete(); } diff --git a/routes/items/itemsRouter.js b/routes/items/itemsRouter.js index 540edea..081cf32 100644 --- a/routes/items/itemsRouter.js +++ b/routes/items/itemsRouter.js @@ -34,12 +34,10 @@ router.delete('/:id', async (req, res) => { } } catch (err) { // console.log(err); - res - .status(500) - .json({ - message: - 'There was an error while trying to delete an item from the data base', - }); + res.status(500).json({ + message: + 'There was an error while trying to delete an item from the data base', + }); } }); diff --git a/routes/users/usersModel.js b/routes/users/usersModel.js index d4d0bc0..8cdc6fb 100644 --- a/routes/users/usersModel.js +++ b/routes/users/usersModel.js @@ -43,4 +43,3 @@ function update(id, changes) { .update(changes, '*') .then(() => getUserById(id1)); } - From 82cd796238237d1b92634c89143fbc2442af1511 Mon Sep 17 00:00:00 2001 From: Erik Sandoval Date: Sun, 8 Sep 2019 19:57:07 -0700 Subject: [PATCH 2/6] creating renter_table --- .../migrations/20190908194354_renter_table.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 data/migrations/20190908194354_renter_table.js diff --git a/data/migrations/20190908194354_renter_table.js b/data/migrations/20190908194354_renter_table.js new file mode 100644 index 0000000..bb10c6c --- /dev/null +++ b/data/migrations/20190908194354_renter_table.js @@ -0,0 +1,22 @@ +exports.up = function(knex) { + return knex.schema.table('renter_table', function(tbl) { + tbl.increments(); + tbl + .integer('item_id', 255) + .references('id') + .inTable('items') + .notNull(); + tbl + .integer('renter_id', 255) + .references('id') + .inTable('users') + .notNull(); + tbl.decimal('offer_amount', 8, 2).notNull(); + tbl.date('date_from').notNull(); + tbl.date('date_to').notNull(); + tbl.boolean('rent_agree'); + tbl.boolean('returned'); + }); +}; + +exports.down = function(knex) {}; From 03acb207710b02fd0296496584f2b7d145b4a825 Mon Sep 17 00:00:00 2001 From: Erik Sandoval Date: Sun, 8 Sep 2019 19:58:15 -0700 Subject: [PATCH 3/6] added drop table function. --- data/migrations/20190908194354_renter_table.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/migrations/20190908194354_renter_table.js b/data/migrations/20190908194354_renter_table.js index bb10c6c..0492904 100644 --- a/data/migrations/20190908194354_renter_table.js +++ b/data/migrations/20190908194354_renter_table.js @@ -19,4 +19,6 @@ exports.up = function(knex) { }); }; -exports.down = function(knex) {}; +exports.down = function(knex) { + return knex.schema.dropTableIfExists('renter_table'); +}; From bfa101683e5421ff1aac50d787050be544d965b1 Mon Sep 17 00:00:00 2001 From: Erik Sandoval Date: Sun, 8 Sep 2019 20:07:15 -0700 Subject: [PATCH 4/6] fixed create table bug --- .../migrations/20190908194354_renter_table.js | 2 +- data/tech2rent.sqlite3 | Bin 36864 -> 36864 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/data/migrations/20190908194354_renter_table.js b/data/migrations/20190908194354_renter_table.js index 0492904..8c6f443 100644 --- a/data/migrations/20190908194354_renter_table.js +++ b/data/migrations/20190908194354_renter_table.js @@ -1,5 +1,5 @@ exports.up = function(knex) { - return knex.schema.table('renter_table', function(tbl) { + return knex.schema.createTable('renter_table', function(tbl) { tbl.increments(); tbl .integer('item_id', 255) diff --git a/data/tech2rent.sqlite3 b/data/tech2rent.sqlite3 index 1aa0b149a8bffe3062279c3b9518e3c5fb738307..c2bdc239650481c28659eb4614c2c57fd730a047 100644 GIT binary patch delta 624 zcmZozz|^pSX@ayM2Ll5GClJGc=tLc3Sq=t069rzbCI$}nFa~}{zW01yJac)JI78UO zxF&5@6lh`D#M;6dz#t$lF3#8{S(2EPlbYGg%fl|Ns>;|J3+5N4=9Q!t#bdBJor7E* zLtGU?9G!ez6%vq@Oe{nj1fP0>22m4n%hH1x~5@{IoQnVTrllymX~K9NlZECNgn0-G5de(|$$ff5Xq4Kj!T8vwkH!m0oO literal 36864 zcmeHQOKcm*8D5H_D9W}N*GYvShm2zgG9!`P_oE3=(~=^|mSx$J{5TZUh#Zn@EqCbI zr6fAN&@Pe|D9~dsedO9hfTBQeX@U08URo6By+BXxp+JkCd+9$*QY1wssSLPAj9KWh zocH(r|NOI@$G=;5*4>bx3T1U1B29Wtip8XB2uYHZgx^&6HwOP-hu?Ad?Oigr&2O`Pf8c2|22K%{EyGSliE(+OZs1yS;Pwl1OtMB7s&s|&Bz_lN-F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P(V?=S*l$|%SR>fjt_H8=#aAgXy&QPz0M;@ z1qWncvZ>%5;#L6fz=bqWfL{$zh0!{yx%KM!|EZ!%d{Rn9h+Zt9+E`T2+ifd8eviN# znO7(+zYywZjMtQen#OwbW^kAUc)vmSUPy&sZIu?S7Yqmn1OtKr!GK^uFd!HZ3 Date: Sun, 8 Sep 2019 20:16:30 -0700 Subject: [PATCH 5/6] added cancelled property. --- .../migrations/20190908194354_renter_table.js | 1 + data/tech2rent.sqlite3 | Bin 36864 -> 36864 bytes 2 files changed, 1 insertion(+) diff --git a/data/migrations/20190908194354_renter_table.js b/data/migrations/20190908194354_renter_table.js index 8c6f443..b8401b1 100644 --- a/data/migrations/20190908194354_renter_table.js +++ b/data/migrations/20190908194354_renter_table.js @@ -16,6 +16,7 @@ exports.up = function(knex) { tbl.date('date_to').notNull(); tbl.boolean('rent_agree'); tbl.boolean('returned'); + tbl.boolean('cancelled'); }); }; diff --git a/data/tech2rent.sqlite3 b/data/tech2rent.sqlite3 index c2bdc239650481c28659eb4614c2c57fd730a047..d47cc883fdf1144f9c5fe621937001b760e95f57 100644 GIT binary patch delta 275 zcmZozz|^pSX@az%Gy?+zClJGc*+d;*d{qSf&BzWPJVJ?NoIcDWO23$ljS(|IM{gDz&3AI;z<-@6qwv1r^+V6nlVL> zfAV@cEf90E4&UVaavC7!Bs1R0yz)jMX0I;KWLJ4j5VKW_dvb}q8i?7X&oz00yf%p0 xsLwh1qP#W>kXgG);Tb=hfH)(wDd*$~d?K3+xC3}OfY!1DG01w>&4LCm_yNo|Jy`$% delta 241 zcmZozz|^pSX@ayM2Ll5GClJGc=tLc3Sq=t069rzbCI$}nFa~}{zW01yJac)JI78UO zxF&5@6lh_Y#JX|vU9R%Ux!m=W`#35l%W;}9a%~P{*JGAo5D*s^XKa%!NleN~&1~l7 zVHa0bWo(Vzyqi^-aq?%j#|ICmDdC@^R<{Km&mJum^u1PlNZQqgP7U+jFT_QYqJ2E>6;Xu@w0J= WGcucUPM*LgvdMruU^BPFSAGB>M?-=D From 8db58713760c051ab8b7f6f216207839b45b8187 Mon Sep 17 00:00:00 2001 From: Erik Sandoval Date: Sun, 8 Sep 2019 20:28:18 -0700 Subject: [PATCH 6/6] trying renting item --- routes/items/itemsModel.js | 5 +++++ routes/items/itemsRouter.js | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/routes/items/itemsModel.js b/routes/items/itemsModel.js index 22a7b54..b180e84 100644 --- a/routes/items/itemsModel.js +++ b/routes/items/itemsModel.js @@ -6,6 +6,7 @@ module.exports = { getItemById, updateItem, deleteItem, + rentItem, }; function getAll() { @@ -28,3 +29,7 @@ function deleteItem(id) { .where({ id }) .delete(); } + +function rentItem(body) { + return db('renter_table').insert(body); +} diff --git a/routes/items/itemsRouter.js b/routes/items/itemsRouter.js index 081cf32..9bcefa1 100644 --- a/routes/items/itemsRouter.js +++ b/routes/items/itemsRouter.js @@ -41,4 +41,16 @@ router.delete('/:id', async (req, res) => { } }); +router.post('/rent', async (req, res) => { + try { + const body = req.params; + const rentRequest = await itemsModel.rentItem(body); + res.status(201).json(rentRequest); + } catch (err) { + res.status(500).json({ + message: 'There was an error while trying to rent this item', + }); + } +}); + module.exports = router;