Skip to content

Commit

Permalink
[ft-166240824-v2] marge migration updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramadhan0 committed Jun 24, 2019
2 parents fc92c29 + 9915d43 commit e5354dd
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 58 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ coverage

# Migrations
src/api/migrations

# Seeders
src/api/seeders
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ cache:
- 'node_modules'
script:
- npm test

before_script:
- psql -c 'create database travis_ci_test;' -U postgres
services:
- postgresql
deploy:
provider: heroku
api_key:
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![Maintainability](https://api.codeclimate.com/v1/badges/c05960d83e2ec9822111/maintainability)](https://codeclimate.com/github/andela/savage_rangers-ah/maintainability)
=======


# Authors Haven - A Social platform for the creative at heart.

## Vision
Expand Down Expand Up @@ -412,3 +411,26 @@ No additional parameters required
### Get Tags

`GET /api/tags`

## Getting started

### 1. Installation steps

- Clone the repo using:

`git clone https://github.com/andela/savage_rangers-ah.git`

- Install dependencies by runing

`npm install`

- Create a `.env` file at the root of the project and fill out the variables you can find in `.env.example` file

- Run `npm run setup:dev` to create the tables in the database

- You can now run `npm start` to start the server

### 2. Steps for running tests

- Run tests
`npm test` or `npm ts`
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
"main": "index.js",
"scripts": {
"start": "babel-node src/index.js",
"test": "npm run setup && NODE_ENV=test nyc --reporter=html --reporter=text --reporter=lcov ./node_modules/.bin/mocha ./tests/* --require @babel/register --timeout 4000 --exit",
"setup": "NODE_ENV=test npm run migrate:undo && NODE_ENV=test npm run migrate && NODE_ENV=test npm run seed",
"test": "npm run setup:test && NODE_ENV=test nyc --reporter=html --reporter=text --reporter=lcov ./node_modules/.bin/mocha ./tests/* --require @babel/register --timeout 4000 --exit",
"dev": "NODE_ENV=development nodemon --exec babel-node src/index.js",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"eslint": "eslint . --cache --fix",
"setup": "NODE_ENV=test npm run migrate:undo && NODE_ENV=test npm run migrate && NODE_ENV=test npm run seed",
"setup:test": "NODE_ENV=test npm run migrate:undo && NODE_ENV=test npm run migrate && NODE_ENV=test npm run seed",
"setup:dev": "NODE_ENV=development npm run migrate:undo && NODE_ENV=development npm run migrate && NODE_ENV=development npm run seed",
"precommit": "lint-staged",
"migrate": "node_modules/.bin/sequelize db:migrate",
"seed": "node_modules/.bin/sequelize db:seed:all",
Expand Down Expand Up @@ -78,7 +80,8 @@
"exclude": [
"src/configs/environments.js",
"src/index.js",
"src/configs/passport.js"
"src/configs/passport.js",
"src/index.js"
]
},
"author": "Andela Simulations Programme",
Expand Down
2 changes: 1 addition & 1 deletion src/api/controllers/password.reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class PasswordReset {
userName: username,
buttonText: 'RESET',
message:
"You are receiving this email beacause you've requested the recovery "
"You are receiving this email because you've requested the recovery "
+ 'of your Authors Heaven password. Kindly click the button below.'
});

Expand Down
1 change: 1 addition & 0 deletions src/api/controllers/socialAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class socialLogin {
provider: req.user.provider,
uniqueId: req.user.id
});
console.log(existingUser.dataValues);
const token = generateToken({ username: req.user.displayName, id: req.user.id },
process.env.TOKEN_KEY);
return res.status(status.CREATED).json({ user: { ...existingUser.get(), token } });
Expand Down
4 changes: 3 additions & 1 deletion src/api/migrations/20190620192200-create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default {
type: Sequelize.STRING
},
email: {
type: Sequelize.STRING
type: Sequelize.STRING,
unique: true
},
password: {
type: Sequelize.STRING
Expand Down Expand Up @@ -66,5 +67,6 @@ export default {
type: Sequelize.DATE
}
}),
// eslint-disable-next-line no-unused-vars
down: (queryInterface, Sequelize) => queryInterface.dropTable('Users')
};
51 changes: 51 additions & 0 deletions src/api/migrations/20190624064739-create-test-articl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export default {
up: (queryInterface, Sequelize) => queryInterface.createTable('Articles', {
id: {
allowNull: false,
unique: true,
primaryKey: true,
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4
},
title: {
type: Sequelize.STRING,
allowNull: false
},
slug: {
type: Sequelize.STRING,
allowNull: false,
unique: true
},
description: {
type: Sequelize.STRING,
allowNull: false
},
body: {
type: Sequelize.TEXT,
allowNull: false
},
tagList: {
type: Sequelize.ARRAY(Sequelize.TEXT),
allowNull: false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
},
userId: {
type: Sequelize.INTEGER,
references: {
model: 'Users',
key: 'id'
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
allowNull: false
}
}),
down: (queryInterface, Sequelize) => queryInterface.dropTable('Articles')
};
10 changes: 10 additions & 0 deletions src/api/models/test-articl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
module.exports = (sequelize, DataTypes) => {
const test - articl = sequelize.define('test-articl', {
name: DataTypes.STRING
}, {});
test - articl.associate = function(models) {
// associations can be defined here
};
return test - articl;
};
25 changes: 25 additions & 0 deletions src/api/seeders/20190621184055-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
up: (queryInterface, Sequelize) =>
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.
*/
queryInterface.bulkInsert('Users',
[
{
username: 'BurindiAlain4',
email: 'alain1@gmail.com',
password: 'password23423',
createdAt: new Date(),
updatedAt: new Date()
}
],
{}),

down: (queryInterface, Sequelize) =>
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.
*/
queryInterface.bulkDelete('Users', null, {})
};
50 changes: 1 addition & 49 deletions src/configs/environments.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import dotenv from 'dotenv';

// import passport from 'passport';
// import FacebookStrategy from 'passport-facebook';
// import { OAuth2Strategy } from 'passport-google-oauth';
// import TwitterStrategy from 'passport-twitter';

dotenv.config();
const env = process.env.NODE_ENV;
const appPort = process.env.PORT;
const env = process.env.NODE_ENV;
const jwtSecret = process.env.TOKEN_KEY;
const mailerEmail = process.env.MAILER_EMAIL;
const mailerToken = process.env.MAILER_API_KEY;
Expand Down Expand Up @@ -88,49 +83,6 @@ const environments = [
}
];

// const {
// GOOGLE_CLIENT_ID,
// GOOGLE_CLIENT_SECRET,
// GOOGLE_CALLBACK,
// FACEBOOK_CLIENT_ID,
// FACEBOOK_CLIENT_SECRET,
// FACEBOOK_CALLBACK,
// TWITTER_CLIENT_ID,
// TWITTER_CLIENT_SECRET,
// TWITTER_CALLBACK
// } = process.env;

// passport.use(new OAuth2Strategy({
// clientID: GOOGLE_CLIENT_ID,
// clientSecret: GOOGLE_CLIENT_SECRET,
// callbackURL: GOOGLE_CALLBACK,
// profileFields: ['name', 'photos', 'email']
// },
// (accessToken, refreshToken, profile, done) => done(null, profile)));

// passport.use(new FacebookStrategy({
// clientID: FACEBOOK_CLIENT_ID,
// clientSecret: FACEBOOK_CLIENT_SECRET,
// callbackURL: FACEBOOK_CALLBACK,
// profileFields: ['name', 'photos', 'email']
// },
// (accessToken, refreshTocken, profile, done) => done(null, profile)));

// passport.use(new TwitterStrategy({
// consumerKey: TWITTER_CLIENT_ID,
// consumerSecret: TWITTER_CLIENT_SECRET,
// callbackURL: TWITTER_CALLBACK,
// profile: ['name', 'photo', 'email']
// },
// (accessToken, refreshTocken, profile, done) => {
// done(null, profile);
// }));

// passport.serializeUser((user, done) => done(null, user));
// passport.deserializeUser((user, done) => done(null, user));

const currentEnv = environments.find(el => el.name === env.toLocaleLowerCase());

// // export default { currentEnv, env, passport };

module.exports = currentEnv;
4 changes: 2 additions & 2 deletions src/helpers/Mailer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import env from '../../configs/environments';

mailer.setApiKey(env.mailerToken);

export default async (messageTitle, emailSubject, reciever, operation, userData) => {
export default (messageTitle, emailSubject, reciever, operation, userData) => {
try {
const messageBody = templates[operation](userData);
const message = {
Expand All @@ -30,7 +30,7 @@ export default async (messageTitle, emailSubject, reciever, operation, userData)
</div>
</div>`
};
return await mailer.send(message);
return mailer.send(message);
} catch (error) {
return error;
}
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/sequelize.initializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import models from '../api/models';

models.SequelizeMeta.truncate({ truncate: { cascade: false } });

0 comments on commit e5354dd

Please sign in to comment.