-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from makon57/finishings
Finishings
- Loading branch information
Showing
102 changed files
with
6,576 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
'config': path.resolve('config', 'database.js'), | ||
'models-path': path.resolve('db', 'models'), | ||
'seeders-path': path.resolve('db', 'seeders'), | ||
'migrations-path': path.resolve('db', 'migrations') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
const db = require('./db/models'); | ||
|
||
const loginUser = (req, res, user) => { | ||
req.session.auth = { | ||
userId: user.id, | ||
}; | ||
}; | ||
|
||
const logoutUser = (req, res) => { | ||
delete req.session.auth; | ||
}; | ||
|
||
const requireAuth = (req, res, next) => { | ||
if (!res.locals.authenticated) { | ||
return res.redirect('/login'); | ||
} | ||
return next(); | ||
}; | ||
|
||
const restoreUser = async (req, res, next) => { | ||
// Log the session object to the console | ||
// to assist with debugging. | ||
console.log(req.session); | ||
|
||
if (req.session.auth) { | ||
const { userId } = req.session.auth; | ||
|
||
try { | ||
const user = await db.User.findByPk(userId); | ||
|
||
if (user) { | ||
res.locals.authenticated = true; | ||
res.locals.user = user; | ||
// console.log(res.locals.user) | ||
next(); | ||
} | ||
} catch (err) { | ||
res.locals.authenticated = false; | ||
next(err); | ||
} | ||
} else { | ||
res.locals.authenticated = false; | ||
next(); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
loginUser, | ||
logoutUser, | ||
requireAuth, | ||
restoreUser, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Users', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
username: { | ||
unique: true, | ||
allowNull: false, | ||
type: Sequelize.STRING(50) | ||
}, | ||
email: { | ||
unique: true, | ||
allowNull: false, | ||
type: Sequelize.STRING(255) | ||
}, | ||
password: { | ||
allowNull: false, | ||
type: Sequelize.STRING | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Users'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('TrailLists', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
name: { | ||
unique: true, | ||
allowNull: false, | ||
type: Sequelize.STRING(255) | ||
}, | ||
userId: { | ||
references: { model: "Users" }, | ||
allowNull: false, | ||
type: Sequelize.INTEGER | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('TrailLists'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('TrailLists', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
name: { | ||
unique: true, | ||
allowNull: false, | ||
type: Sequelize.STRING(255) | ||
}, | ||
userId: { | ||
references: { model: "Users" }, | ||
allowNull: false, | ||
type: Sequelize.INTEGER | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('TrailLists'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Trails', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
name: { | ||
unique:true, | ||
allowNull: false, | ||
|
||
type: Sequelize.STRING(50) | ||
}, | ||
description: { | ||
allowNull: false, | ||
type: Sequelize.TEXT | ||
}, | ||
state: { | ||
allowNull: false, | ||
type: Sequelize.STRING(50) | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Trails'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Joins', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
trailId: { | ||
allowNull: false, | ||
references: { model: "Trails" }, | ||
type: Sequelize.INTEGER | ||
}, | ||
trailListId: { | ||
allowNull: false, | ||
references: { model: "TrailLists" }, | ||
type: Sequelize.INTEGER | ||
}, | ||
hasVisited: { | ||
type: Sequelize.BOOLEAN | ||
}, | ||
wantToVisit: { | ||
type: Sequelize.BOOLEAN | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Joins'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Reviews', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
trailId: { | ||
allowNull: false, | ||
references: { model: "Trails" }, | ||
type: Sequelize.INTEGER | ||
}, | ||
userId: { | ||
references: { model: "Users" }, | ||
allowNull: false, | ||
type: Sequelize.INTEGER | ||
}, | ||
rating: { | ||
allowNull: false, | ||
type: Sequelize.INTEGER | ||
}, | ||
text: { | ||
allowNull: false, | ||
type: Sequelize.TEXT | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Reviews'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
module.exports = (sequelize, DataTypes) => { | ||
const Join = sequelize.define('Join', { | ||
trailId: DataTypes.INTEGER, | ||
trailShelfId: DataTypes.INTEGER, | ||
hasVisited: DataTypes.BOOLEAN, | ||
wantToVisit: DataTypes.BOOLEAN | ||
}, {}); | ||
Join.associate = function(models) { | ||
// Join.belongsTo(models.TrailList, {foreignKey: 'trailListId'}) | ||
// Join.hasMany(models.Trail, {foreignKey:'trailId'}) | ||
}; | ||
return Join; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
module.exports = (sequelize, DataTypes) => { | ||
const Review = sequelize.define('Review', { | ||
trailId: DataTypes.INTEGER, | ||
userId: DataTypes.INTEGER, | ||
rating: DataTypes.INTEGER, | ||
text: DataTypes.TEXT | ||
}, {}); | ||
Review.associate = function(models) { | ||
Review.belongsTo(models.User,{foreignKey:'userId'}) | ||
Review.belongsTo(models.Trail, {foreignKey: 'trailId'}) | ||
}; | ||
return Review; | ||
}; |
Oops, something went wrong.