Skip to content

Commit

Permalink
updated routes files and added comments throughout
Browse files Browse the repository at this point in the history
  • Loading branch information
fredm23579 committed Apr 13, 2024
1 parent 375b911 commit 3a3b208
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 164 deletions.
28 changes: 14 additions & 14 deletions config/connection.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const Sequelize = require('sequelize');
require('dotenv').config();
const Sequelize = require('sequelize'); // import sequelize (https://sequelize.org/docs/v6/getting-started/)
require('dotenv').config(); // import dotenv (https://www.npmjs.com/package/dotenv) (https://github.com/sindresorhus/dotenv)

let sequelize;
let sequelize; // sequelize object (https://sequelize.org/docs/v6/getting-started/)

if (process.env.JAWSDB_URL) {
sequelize = new Sequelize(process.env.JAWSDB_URL);
} else {
sequelize = new Sequelize(
process.env.DB_NAME,
process.env.DB_USER,
process.env.DB_PASSWORD,
if (process.env.JAWSDB_URL) { // if JAWSDB_URL is defined (https://devcenter.heroku.com/articles/jawsdb)
sequelize = new Sequelize(process.env.JAWSDB_URL); // use JAWSDB_URL (https://devcenter.heroku.com/articles/jawsdb)
} else { // if JAWSDB_URL is not defined (https://devcenter.heroku.com/articles/jawsdb)
sequelize = new Sequelize( // use local database (https://sequelize.org/docs/v6/getting-started/)
process.env.DB_NAME, // database name (https://sequelize.org/docs/v6/getting-started/)
process.env.DB_USER, // database user (https://sequelize.org/docs/v6/getting-started/)
process.env.DB_PASSWORD, // database password (https://sequelize.org/docs/v6/getting-started/)
{
host: 'localhost',
dialect: 'mysql',
port: 3306
host: 'localhost', // database host (https://sequelize.org/docs/v6/getting-started/)
dialect: 'mysql', // database dialect (https://sequelize.org/docs/v6/getting-started/)
port: 3306 // database port (https://sequelize.org/docs/v6/getting-started/)
}
);
}

module.exports = sequelize;
module.exports = sequelize; // export sequelize object (https://sequelize.org/docs/v6/getting-started/)
110 changes: 55 additions & 55 deletions controllers/api-routes.js

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

50 changes: 25 additions & 25 deletions models/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@ const sequelize = require('../config/connection');

class Comment extends Model {} // Comment model (https://sequelize.org/docs/v6/core-concepts/model-basics/)

Comment.init(
Comment.init( // Comment model (https://sequelize.org/docs/v6/core-concepts/model-basics/)
{
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
id: { // id column (https://sequelize.org/docs/v6/core-concepts/model-basics/#column-options)
type: DataTypes.INTEGER, // data type (https://sequelize.org/master/identifiers.html)
allowNull: false, // allow null (https://sequelize.org/docs/v6/core-concepts/model-basics/#allowing-nulls)
primaryKey: true, // primary key (https://sequelize.org/docs/v6/core-concepts/model-basics/#primary-keys)
autoIncrement: true, // auto increment (https://sequelize.org/docs/v6/core-concepts/model-basics/#auto-incrementing)
},
content: {
type: DataTypes.STRING,
allowNull: false,
content: { // content column (https://sequelize.org/docs/v6/core-concepts/model-basics/#column-options)
type: DataTypes.STRING, // data type (https://sequelize.org/master/identifiers.html)
allowNull: false, // allow null (https://sequelize.org/docs/v6/core-concepts/model-basics/#allowing-nulls)
},
creator: {
type: DataTypes.STRING,
references: {
model: 'user',
key: 'username',
creator: { // foreign key for username (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys) (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys)
type: DataTypes.STRING, // data type (https://sequelize.org/master/identifiers.html) (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys)
references: { // foreign key for username (https //sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys) (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys)
model: 'user', // model (https://sequelize.org/docs /v6/core-concepts/assocs/#foreign-keys) (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys)
key: 'username', // foreign key for username (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys) (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys) (https://sequelize.org
}
},
date_created: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW, // records date/time at time of creation
date_created: { // https://sequelize.org/docs/v6/core-concepts/model-basics/#column-options (https://sequelize.org/docs/v6/core-concepts/model-basics/#column-options)
type: DataTypes.DATE, // data type (https://sequelize.org/master/identifiers.html) (https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types)
allowNull: false, // allow null (https://sequelize.org/docs/v6/core-concepts/model-basics/#allowing-nulls)
defaultValue: DataTypes.NOW, // records date/time at time of creation (https://sequelize.org/docs/v6/core-concepts/model-basics/#default-values)
},
post_id: { // foreign key for post id (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys)
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'post',
key: 'id', // foreign key for post id
post_id: { // foreign key for post id (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys) (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys)
type: DataTypes.INTEGER, // data type (https://sequelize.org/master/identifiers.html) (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys)
allowNull: false, // allow null (https://sequelize.org/docs/v6/core-concepts/model-basics/#allowing-nulls) (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys)
references: { // foreign key for post id (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys) (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys)
model: 'post', // model (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys) (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys)
key: 'id', // foreign key for post id (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys) (https://sequelize.org/docs/v6/core-concepts/assocs/#foreign-keys)
}
}
},
Expand All @@ -44,4 +44,4 @@ Comment.init(
}
);

module.exports = Comment;
module.exports = Comment; // export Comment model (https://sequelize.org/docs/v6/core-concepts/model-basics/) (https://sequelize.org/docs/v6/core-concepts/model-basics/) (https://github
Loading

0 comments on commit 3a3b208

Please sign in to comment.