Skip to content

Commit

Permalink
chore(documentation): fix merge conflict
Browse files Browse the repository at this point in the history
[Finishes #167891569]
  • Loading branch information
daniellamarr authored and meetKazuki committed Aug 20, 2019
2 parents 07cf21d + 973977f commit 0fe1518
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 21 deletions.
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
* text eol=lf

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout. e.g *.c text, *.h text

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=lf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ typings/

# End of https://www.gitignore.io/api/node

application port
notes.md
package-lock.json
.editorconfig
10 changes: 10 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require('@babel/register')
const path = require('path');

module.exports = {
'config': path.resolve('./src/database/config', 'config.js'),
'models-path': path.resolve('./src/database/models'),
'seeders-path': path.resolve('./src/database/seeders'),
'migrations-path': path.resolve('./src/database/migrations')
}

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
"devstart": "nodemon --exec babel-node src/index.js",
"lint": "eslint --fix ./src/**/*.js",
"test": "cross-env NODE_ENV=test nyc mocha --require @babel/register --require @babel/polyfill --exit",
"coverage": "nyc report --reporter=text-lcov | coveralls"
"coverage": "nyc report --reporter=text-lcov | coveralls",
"migrate": "sequelize db:migrate",
"migrate:undo": "sequelize db:migrate:undo:all",
"seed": "sequelize db:seed:all",
"db:reset": "npm run migrate:undo && npm run migrate && npm run seed"
},
"author": "Andela Simulations Programme",
"license": "MIT",
Expand All @@ -45,6 +49,9 @@
"passport-local": "^1.0.0",
"pg": "^7.12.1",
"request": "^2.87.0",
"sequelize": "^5.15.0",
"sequelize-cli": "^5.5.0",
"swagger-ui-express": "^4.0.7",
"underscore": "^1.9.1"
},
"devDependencies": {
Expand Down
4 changes: 0 additions & 4 deletions src/config/index.js

This file was deleted.

Empty file removed src/database/config.js
Empty file.
35 changes: 35 additions & 0 deletions src/database/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import dotenv from 'dotenv';

dotenv.config();

const { DB_DEV_NAME, DB_USER_NAME, DB_PASSWORD } = process.env;

const dialect = 'postgres';

module.exports = {
development: {
username: DB_USER_NAME,
password: DB_PASSWORD,
database: DB_DEV_NAME,
host: '127.0.0.1',
port: process.env.DB_PORT,
dialect
},
test: {
username: DB_USER_NAME,
password: DB_PASSWORD,
database: process.env.DB_TEST_NAME,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
dialect
},
production: {
username: process.env.PRODUCTION_USERNAME,
password: process.env.PRODUCTION_PASSWORD,
database: process.env.PRODUCTION_DATABASE,
host: process.env.PRODUCTION_HOST,
port: process.env.PRODUCTION_PORT,
dialect,
ssl: true
}
};
39 changes: 39 additions & 0 deletions src/database/migrations/20190817131405-create-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('Users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
first_name: {
type: Sequelize.STRING
},
last_name: {
type: Sequelize.STRING
},
email: {
type: Sequelize.STRING
},
password: {
type: Sequelize.STRING
},
role: {
type: Sequelize.STRING
},
gender: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn('now')
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn('now')
}
}),
down: queryInterface => queryInterface.dropTable('Users')
};
40 changes: 40 additions & 0 deletions src/database/models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import fs from 'fs';
import path from 'path';
import Sequelize from 'sequelize';
import configSetup from '../config/config';

const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = configSetup[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
);
}

fs.readdirSync(__dirname)
.filter(file => (file
.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js'))
.forEach((file) => {
const model = sequelize.import(path.join(__dirname, file));
db[model.name] = model;
});

Object.keys(db).forEach((modelName) => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

export default db;
18 changes: 18 additions & 0 deletions src/database/models/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = (sequelize, DataTypes) => {
const Users = sequelize.define(
'Users',
{
first_name: DataTypes.STRING,
last_name: DataTypes.STRING,
email: DataTypes.STRING,
password: DataTypes.STRING,
role: DataTypes.STRING,
gender: DataTypes.STRING
},
{}
);
Users.associate = () => {
// associations can be defined here
};
return Users;
};
52 changes: 52 additions & 0 deletions src/database/seeders/20190817134840-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module.exports = {
up: queryInterface => queryInterface.bulkInsert('Users', [
{
first_name: 'Femi',
last_name: 'Tijani',
email: 'tjhakeemus@gmail.com',
password: '12345678',
role: 'Software Engineer',
gender: 'male'
},
{
first_name: 'Desmond',
last_name: 'Edem',
email: 'kukiito@gmail.com',
password: '12345678',
role: 'Software Engineer',
gender: 'male'
},
{
first_name: 'Maxwell',
last_name: 'Eke',
email: 'muximusekeh@gmail.com',
password: '12345678',
role: 'Software Engineer',
gender: 'male'
},
{
first_name: 'Muheed',
last_name: 'Olakunle',
email: 'olakunlemuheeb@gmail.com',
password: '12345678',
role: 'Software Engineer',
gender: 'male'
},
{
first_name: 'Peter',
last_name: 'Tyonum',
email: 'kukiito@gmail.com',
password: '12345678',
role: 'Software Engineer',
gender: 'male'
},
{
first_name: 'Babatunde',
last_name: 'Ogedengbe',
email: 'kukiito@gmail.com',
password: '12345678',
role: 'Software Engineer',
gender: 'male'
}
])
};
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import express from 'express';
import dotenv from 'dotenv';
import swaggerUi from 'swagger-ui-express';
import router from './routes';
import swaggerDoc from '../swagger.json';

const app = express();
dotenv.config();
Expand All @@ -14,6 +16,10 @@ app.get('/', (req, res) => {
});
});

/**
* Tip from: https://blog.cloudboost.io/adding-swagger-to-existing-node-js-project-92a6624b855b
*/
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDoc));
app.use('/api/v1', router);

const port = process.env.PORT || 3000;
Expand Down
16 changes: 0 additions & 16 deletions src/models/index.js

This file was deleted.

48 changes: 48 additions & 0 deletions swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"openapi": "3.0.1",
"info": {
"title": "Barefoot Nomad API",
"description": "Barefoot Nomad makes company global travel and accommodation easy and convenient for the strong workforce of savvy members of staff, by leveraging the modern web.",
"contact": {
"email": "team-banshee@barefoot-nomad.com"
},
"version": "1.0.0"
},
"externalDocs": {
"description": "The Github Repository",
"url": "https://github.com/andela/banshee-bn-backend"
},
"servers": [
{
"url": "/api/v1"
},
{
"url": "/"
}
],
"tags": [
{
"name": "Welcome",
"description": "The root endpoint"
},
{
"name": "Users",
"description": "Operations related to Users authentication"
}
],
"paths": {
"/": {
"get": {
"tags": [
"Welcome"
],
"summary": "The root endpoint",
"responses": {
"200": {
"description": "Success"
}
}
}
}
}
}

0 comments on commit 0fe1518

Please sign in to comment.