Skip to content

Commit 926afe2

Browse files
authored
Merge pull request #44 from labs12-linked-in/brandon-borrero
Brandon borrero
2 parents c186bc5 + 5f00151 commit 926afe2

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ PORT=9001
22

33
DB_ENV=development
44

5-
DB_PASSWORD=matt123!
5+
DB_PASSWORD=thisisabadpassword

data/migrations/20190424215805_initial_tables.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ exports.up = function(knex) {
44
table.increments()
55
table.string('first_name').notNullable()
66
table.string('last_name').notNullable()
7+
table.boolean('pro').defaultTo(false)
78
table
89
.string('user_id')
910
.notNullable()

user/user-model.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = {
77
verifyUser,
88
addUser,
99
deleteUser,
10-
generateToken
10+
generateToken,
11+
upgradeUser
1112
}
1213

1314
function generateToken() {
@@ -54,3 +55,13 @@ async function deleteUser(id) {
5455

5556
return deleted
5657
}
58+
59+
async function upgradeUser(user_id) {
60+
await db('users')
61+
.update({ pro: true })
62+
.where({ user_id })
63+
64+
return db('users')
65+
.where({ user_id })
66+
.first()
67+
}

user/user-routes.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,25 @@ router.delete('/banish', (req, res) => {
7373
})
7474
})
7575

76+
// upgrade user
77+
router.post('/upgrade', (req, res) => {
78+
const { user_id } = req.body
79+
80+
if (!user_id) {
81+
res.status(400).json({ message: 'Please provide user id.' })
82+
}
83+
84+
User.upgradeUser(user_id)
85+
.then(response => {
86+
console.log(response, 'res')
87+
res
88+
.status(200)
89+
.json({ message: 'user has been upgraded to a pro account!' })
90+
})
91+
.catch(error => {
92+
console.log(error, 'er')
93+
res.status(500).json({ err: 'Could not upgrade user', error })
94+
})
95+
})
96+
7697
module.exports = router

0 commit comments

Comments
 (0)