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

Finishings #4

Merged
merged 86 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
4b16870
push test
lemlooma Jun 28, 2021
6b66b8b
removed hi --testing
WellerJay118 Jun 28, 2021
eceb0dc
added hi again
makon57 Jun 28, 2021
74e5f51
test
Simonvargas Jun 28, 2021
b3d95bb
.env
lemlooma Jun 28, 2021
55bc722
.gitignore
lemlooma Jun 28, 2021
82d2b75
.env
lemlooma Jun 28, 2021
0d42e17
test
lemlooma Jun 28, 2021
4f09c2b
test
lemlooma Jun 28, 2021
5e3c6fe
hi
Simonvargas Jun 28, 2021
e30062c
test
lemlooma Jun 28, 2021
79060bd
auth.js
lemlooma Jun 28, 2021
f928ccc
pushing
lemlooma Jun 28, 2021
999cde4
sequelizeFIX
lemlooma Jun 28, 2021
751c6c9
models added
lemlooma Jun 28, 2021
ad9ccb4
updated migrations
lemlooma Jun 28, 2021
b343d4f
databases
Simonvargas Jun 28, 2021
2499f86
auth
Simonvargas Jun 28, 2021
24ab96a
updated database
lemlooma Jun 28, 2021
ba175dc
edited
lemlooma Jun 29, 2021
c1700f5
edited
lemlooma Jun 29, 2021
01135e3
css added
lemlooma Jun 29, 2021
8bebbf3
done with login and working on signup
makon57 Jun 29, 2021
8de044d
login
lemlooma Jun 29, 2021
33a8dd3
more
lemlooma Jun 29, 2021
fd0cd1a
login errrors
makon57 Jun 29, 2021
9178901
edit
lemlooma Jun 29, 2021
9294dd1
FINALLY IT WORKS
lemlooma Jun 29, 2021
10be5b5
.
lemlooma Jun 29, 2021
774aa45
done with demo and logout
makon57 Jun 29, 2021
dc53dec
seeder demo
makon57 Jun 29, 2021
1b8a396
seeder added
lemlooma Jun 29, 2021
5ea8fea
edited
lemlooma Jun 29, 2021
3be7c9b
pushed
lemlooma Jun 29, 2021
c66cf24
pushed
lemlooma Jun 29, 2021
c43af07
added css
lemlooma Jun 29, 2021
92de094
ready
lemlooma Jun 29, 2021
946d225
sign up
lemlooma Jun 29, 2021
609ad07
AHHHHHH
lemlooma Jun 29, 2021
bde2b04
fixed the seeders
makon57 Jun 30, 2021
7567def
done with labeling
makon57 Jun 30, 2021
11593ab
tankering done
makon57 Jun 30, 2021
9f0f7cd
Merge pull request #2 from makon57/tanker
Simonvargas Jun 30, 2021
0ff790b
edited migrations
lemlooma Jun 30, 2021
ffc816a
images
Simonvargas Jun 30, 2021
745b765
seed some
lemlooma Jun 30, 2021
4d085ca
trail seeds
WellerJay118 Jun 30, 2021
975b587
commented out unused seeders
WellerJay118 Jun 30, 2021
f177642
trail images uploaded
WellerJay118 Jun 30, 2021
e36bb1a
reviews
lemlooma Jun 30, 2021
6ed1ed6
homeage erros
makon57 Jun 30, 2021
3c0d57a
done fixing trail
makon57 Jun 30, 2021
14e0ace
done with homepage css
makon57 Jun 30, 2021
79b20e4
partially done with homepage
makon57 Jun 30, 2021
e912969
tanker stuff
makon57 Jun 30, 2021
17a56ab
done with the nav bar and header
makon57 Jun 30, 2021
eca0872
styling in the header
makon57 Jun 30, 2021
77e602c
styling of homepage
makon57 Jul 1, 2021
01f11de
done withh login signup on HP
makon57 Jul 1, 2021
514ce93
working on the search selection pseudo
makon57 Jul 1, 2021
378546a
wow
lemlooma Jul 1, 2021
67c44b5
wow
lemlooma Jul 1, 2021
46e8d55
wow
lemlooma Jul 1, 2021
a51aa02
comment
Simonvargas Jul 1, 2021
e19f89e
no comment
Simonvargas Jul 1, 2021
a60fd2e
simon
Simonvargas Jul 1, 2021
7a9d548
seeding reviews and users
makon57 Jul 1, 2021
c727433
reviews
makon57 Jul 1, 2021
12d7d25
done with review post and get
makon57 Jul 1, 2021
886e624
progress on edit button
makon57 Jul 1, 2021
4815e3a
everything but put and delete
makon57 Jul 1, 2021
c56536b
done with delete working on edit
makon57 Jul 1, 2021
f578431
things
makon57 Jul 1, 2021
c6900a4
done with CRUD in reviews
makon57 Jul 1, 2021
00822ad
rihana data
makon57 Jul 2, 2021
1134ecf
gotta fix delete
Simonvargas Jul 2, 2021
2a7d70f
push
Simonvargas Jul 2, 2021
8d7a0e0
things
makon57 Jul 2, 2021
7f622f6
done hopefully
makon57 Jul 2, 2021
b605fe9
working on demo
makon57 Jul 2, 2021
460284a
done with that feature for the demo
makon57 Jul 2, 2021
bbc256e
got the none user to trails link to work
makon57 Jul 2, 2021
7c13b1c
clean up
makon57 Jul 2, 2021
cd9e538
submit
makon57 Jul 2, 2021
2cab79d
done with the site!
makon57 Jul 2, 2021
fbc07d1
done
makon57 Jul 2, 2021
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
node_modules/
8 changes: 8 additions & 0 deletions .sequelizerc
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')
};
12 changes: 12 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const session = require('express-session');
const SequelizeStore = require('connect-session-sequelize')(session.Store);
const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
const loginRouter = require('./routes/login');
// const { asyncHandler } = require('./utils');
const signupRouter = require('./routes/signup');
const { restoreUser } = require('./auth')
// const trailsRouter = require('./routes/trails');


const app = express();

Expand Down Expand Up @@ -35,8 +41,13 @@ app.use(
// create Session table if it doesn't already exist
store.sync();

app.use(express.static('images'));
app.use(restoreUser);
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/login', loginRouter);
app.use('/signup', signupRouter);
// app.use('/trails', trailsRouter);

// catch 404 and forward to error handler
app.use(function (req, res, next) {
Expand All @@ -48,6 +59,7 @@ app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
console.log(res.locals.message)

// render the error page
res.status(err.status || 500);
Expand Down
53 changes: 53 additions & 0 deletions auth.js
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,
};
11 changes: 11 additions & 0 deletions config/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ module.exports = {
dialect: 'postgres',
seederStorage: 'sequelize',
},
production: {
use_env_variable: 'DATABASE_URL',
dialect: 'postgres',
seederStorage: 'sequelize',
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false,
},
},
},
};
Binary file modified db/.DS_Store
Binary file not shown.
38 changes: 38 additions & 0 deletions db/migrations/20210628202037-create-users.js
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');
}
};
34 changes: 34 additions & 0 deletions db/migrations/20210628202553-create-trail-list.js
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');
}
};
34 changes: 34 additions & 0 deletions db/migrations/20210628202553-create-trailList.js
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');
}
};
38 changes: 38 additions & 0 deletions db/migrations/20210628202815-create-trail.js
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');
}
};
40 changes: 40 additions & 0 deletions db/migrations/20210628202816-create-joins.js
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');
}
};
42 changes: 42 additions & 0 deletions db/migrations/20210628203040-create-review.js
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');
}
};
14 changes: 14 additions & 0 deletions db/models/join.js
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;
};
14 changes: 14 additions & 0 deletions db/models/review.js
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;
};
Loading