Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add renting options to table #29

Open
wants to merge 7 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions data/migrations/20190724190911_users_reviews.js
Original file line number Diff line number Diff line change
@@ -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');
};
24 changes: 11 additions & 13 deletions data/migrations/20190726130856_update_items_tbl.js
Original file line number Diff line number Diff line change
@@ -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');
});
}
return knex.schema.table('items', function(tbl) {
tbl.dropColumns('city', 'state', 'zipcode', 'condition', 'sub_category');
});
};
25 changes: 25 additions & 0 deletions data/migrations/20190908194354_renter_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
exports.up = function(knex) {
return knex.schema.createTable('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');
tbl.boolean('cancelled');
});
};

exports.down = function(knex) {
return knex.schema.dropTableIfExists('renter_table');
};
31 changes: 17 additions & 14 deletions data/seeds/003_users_reviews.js
Original file line number Diff line number Diff line change
@@ -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',
},
]);
});
};
Binary file modified data/tech2rent.sqlite3
Binary file not shown.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"helmet": "^3.18.0",
"heroku-cli": "^7.0.9",
"jsonwebtoken": "^8.5.1",
"knex": "^0.18.3",
"knex": "^0.18.4",
"morgan": "^1.9.1",
"passport": "^0.4.0",
"passport-google-oauth20": "^2.0.0",
Expand Down
5 changes: 5 additions & 0 deletions routes/items/itemsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
getItemById,
updateItem,
deleteItem,
rentItem,
getItemByCategory,
getItemByCondition,
getItemByZipCode,
Expand Down Expand Up @@ -38,6 +39,10 @@ function deleteItem(id) {
.delete();
}

function rentItem(body) {
return db('renter_table').insert(body);
}

function getItemByCategory(category) {
return db('items').where(category);
}
Expand Down
12 changes: 12 additions & 0 deletions routes/items/itemsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ 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',
});
}
});

router.post('/searchCategory', async (req, res) => {
try {
console.log(req.body, 'something somethign');
Expand Down