Skip to content

Commit

Permalink
Merge de41aae into c177165
Browse files Browse the repository at this point in the history
  • Loading branch information
Veraclins authored Sep 11, 2018
2 parents c177165 + de41aae commit ac99ac2
Show file tree
Hide file tree
Showing 46 changed files with 693 additions and 723 deletions.
13 changes: 9 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
"sourceMaps": true,
"retainLines": true,
"env": {
"test": {
"plugins": [
"istanbul"
"test": {
"plugins": [
["istanbul", {
"exclude": [
"**/server/v1/helpers/copyleaks/Scan.js",
"**/server/v1/middlewares/plagiarismCheck.js"
]
}
}]
]
}
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"main": "server/index.js",
"scripts": {
"test": "npm run test:v1",
"test:v1": "npm run migrate:test && cross-env NODE_ENV=test nyc --reporter=html --reporter=text mocha --timeout 500000 --exit --require babel-register ./server/v1/tests/**/*.test.js",
"test:v1": "npm run migrate:test && cross-env NODE_ENV=test nyc --reporter=html --reporter=text mocha --timeout 20000 --exit --require babel-register ./server/v1/tests/**/*.test.js",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"coveralls": "nyc --reporter=lcov --reporter=text-lcov npm test",
"prestart": "sequelize db:migrate",
"start": "babel-node server/index.js --presets babel-preset-env",
"dev": "cross-env NODE_ENV=development nodemon server/index.js --exec babel-node --presets babel-preset-env",
"migrate:test": "sequelize db:migrate:undo:all --env=test && sequelize db:migrate --env=test && sequelize db:seed:all --env=test",
"migrate:dev": "sequelize db:migrate",
"migrate:reset": "npm run unmigrate:dev && npm run migrate:dev && npm run seed:all",
"unmigrate:dev": "sequelize db:migrate:undo:all",
"seed:all": "sequelize db:seed:all",
"unseed:all": "sequelize db:seed:undo:all"
Expand Down
4 changes: 2 additions & 2 deletions server/config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ const strategies = {
google: {
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_CLIENT_CALLBACK_URL || '/api/auth/google/callback',
callbackURL: process.env.GOOGLE_CALLBACK_URL || '/api/auth/google/callback',
},
facebook: {
clientID: process.env.FACEBOOK_CLIENT_ID,
clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
callbackURL: process.env.FACEBOOK_CLIENT_CALLBACK_URL || '/api/auth/facebook/callback',
callbackURL: process.env.FACEBOOK_CALLBACK_URL || '/api/auth/facebook/callback',
},
twitter: {
consumerKey: 'get_your_own',
Expand Down
7 changes: 3 additions & 4 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ app.all('*', (req, res) => {
app.use((err, req, res) => {
res.status(err.status || 500);
res.json({
errors: {
message: err.message,
error: env === 'production' ? {} : err,
},
status: 'error',
message: err.message,
error: env === 'production' ? {} : err,
});
});
// finally, let's start our server...
Expand Down
9 changes: 1 addition & 8 deletions server/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = CONFIG[env];
const db = {};


let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
const sequelize = new Sequelize(config.database, config.username, config.password, config);

fs
.readdirSync(__dirname)
Expand Down
15 changes: 14 additions & 1 deletion server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default (sequelize, DataTypes) => {

User.associate = (models) => {
User.hasMany(models.Article, {
foreignKey: 'articleId',
foreignKey: 'userId',
as: 'articles',
});
User.hasMany(models.Comment, {
Expand All @@ -73,16 +73,29 @@ export default (sequelize, DataTypes) => {
});
User.hasMany(models.Follow, {
foreignKey: 'followingId',
as: 'following',
onDelete: 'cascade'
});
User.hasMany(models.Follow, {
foreignKey: 'followerId',
as: 'follower',
onDelete: 'cascade'
});
User.hasMany(models.Subscription, {
foreignKey: 'userId',
as: 'subscriptions',
});

User.belongsToMany(models.User, {
through: models.Follow,
foreignKey: 'followerId',
as: 'followers',
});
User.belongsToMany(models.User, {
through: models.Follow,
foreignKey: 'followingId',
as: 'followings',
});
User.hasMany(models.ArticleSubscription, {
foreignKey: 'userId',
as: 'articlesubscriptions',
Expand Down
11 changes: 7 additions & 4 deletions server/seeders/20180807182424-demo-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ module.exports = {
firstName: 'John',
lastName: 'Doe',
username: 'unique',
password: bcrypt.hashSync('passWord4', 10),
email: 'testseeder@test.com',
bio: `John Doe was born in 1977 when he arrived in Los Angeles.
His previous life in Tennessee,
Wisconsin & Baltimore was a great & fertile time but
new music and social changes led him to events that created a life in art.`,
bio: `John Doe was born in 1977 when he arrived in Los Angeles.
His previous life in Tennessee,
Wisconsin & Baltimore was a great & fertile time but
new music and social changes led him to events that created a life in art.`,
image: 'https://www.image.com/example/image/john',
createdAt: '2018-08-08 18:31:22.324',
updatedAt: '2018-08-08 18:31:22.324',
Expand All @@ -19,6 +20,7 @@ module.exports = {
{
firstName: 'simi',
lastName: 'Doe',
password: bcrypt.hashSync('passWord4', 10),
username: 'simi',
email: 'testsimi@test.com',
bio: `John Doe was born in 1977 when he arrived in Los Angeles.
Expand All @@ -33,6 +35,7 @@ module.exports = {
{
firstName: 'Yomi',
lastName: 'Doe',
password: bcrypt.hashSync('passWord4', 10),
username: 'oyomi',
email: 'seayomi@gmail.com',
verified: true,
Expand Down
4 changes: 2 additions & 2 deletions server/seeders/20180808181558-demo-Article.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
slug: 'arts-is-wonderful-120794ujhd',
userId: 1,
categoryId: 5,
createdAt: '2018-08-08 18:31:22.324',
updatedAt: '2018-08-08 18:31:22.324'
createdAt: '2018-07-08 18:31:22.324',
updatedAt: '2018-08-09 18:31:22.324'
},
{
slug: 'the-first-article-by-the-user',
Expand Down
63 changes: 59 additions & 4 deletions server/seeders/20180822123521-demo-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
module.exports = {
up: queryInterface => queryInterface.bulkInsert('Channels', [
{
name: 'user-JohnAwesome',
name: 'user-unique',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'user-Sweetheart',
name: 'user-simi',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
Expand All @@ -17,12 +17,12 @@ module.exports = {
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'user-unique',
name: 'user-JohnAwesome',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'user-simi',
name: 'user-Sweetheart',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
Expand All @@ -35,6 +35,61 @@ module.exports = {
name: 'user-Jane345',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'article-arts-is-wonderful-120794ujhd',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'article-the-first-article-by-the-user',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'article-the-second-article-by-the-user',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'article-the-first-article-by-another-user',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'article-the-second-article-by-another-user',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'article-other-articles-by-other-users',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'article-the-second-article-by-other-user',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'article-unmissable-steps-before-74U33U38N3IHF1',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'article-unmissable-steps-before-74U33U38N3IHF2',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'article-unmissable-steps-before-74U33U38N3IHF3',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
},
{
name: 'article-unmissable-steps-before-74U33U38N3IHF4',
createdAt: '2018-08-01 21:54:49',
updatedAt: '2018-08-04 21:54:49',
}
]),

Expand Down
31 changes: 31 additions & 0 deletions server/seeders/20180910123557-follow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
up: queryInterface => queryInterface.bulkInsert('Follows', [
{
followerId: 4,
followingId: 3,
createdAt: '2018-08-10 18:31:22.324',
updatedAt: '2018-08-10 18:31:22.324'
},
{
followerId: 4,
followingId: 5,
createdAt: '2018-08-10 18:31:22.324',
updatedAt: '2018-08-10 18:31:22.324'
},
{
followerId: 3,
followingId: 4,
createdAt: '2018-08-10 18:31:22.324',
updatedAt: '2018-08-10 18:31:22.324'
},
{
followerId: 3,
followingId: 5,
createdAt: '2018-08-10 18:31:22.324',
updatedAt: '2018-08-10 18:31:22.324'
},
]),

down: () => {
}
};
Loading

0 comments on commit ac99ac2

Please sign in to comment.