Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Commit

Permalink
feat(*): Initial commit.
Browse files Browse the repository at this point in the history
Initial commit. Added basic express app, graphql endpoint, and profile and strength training data
types
  • Loading branch information
Simon Wears committed Mar 16, 2017
0 parents commit aea4923
Show file tree
Hide file tree
Showing 17 changed files with 3,742 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# custom start script
start.sh

# Created by https://www.gitignore.io/api/webstorm,node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


### WebStorm ###
.idea
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.10.0
128 changes: 128 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"name": "healthgraph-middleware",
"version": "0.0.0",
"description": "Healthgraph API middleware",
"main": "src/app.js",
"license": "MIT",
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"devDependencies": {
"babel-eslint": "^7.1.1",
"commitizen": "^2.9.6",
"conventional-changelog-cli": "^1.3.1",
"cz-conventional-changelog": "^2.0.0",
"eslint": "^3.17.1",
"eslint-config-degree53-core": "^3.0.11",
"eslint-config-degree53-es6": "^3.0.1",
"nodemon": "^1.11.0"
},
"dependencies": {
"cookie-parser": "^1.4.3",
"ejs": "^2.5.6",
"express": "^4.15.2",
"express-graphql": "^0.6.3",
"graphql": "^0.9.1",
"node-polyglot": "^2.2.2",
"superagent": "^3.5.0",
"superagent-promise": "^1.1.0",
"winston": "^2.3.1"
},
"scripts": {
"lint": "eslint src/",
"start": "nodemon src/app.js"
},
"eslintConfig": {
"env": {
"node": true
},
"extends": [
"degree53-core",
"degree53-es6"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"root": true,
"rules": {
"camelcase": 0,
"complexity": [
1,
{
"max": 5
}
],
"id-blacklist": 0,
"no-confusing-arrow": 0,
"no-negated-condition": 1,
"no-shadow": [
2,
{
"allow": [
"name",
"root",
"open",
"status"
],
"builtinGlobals": true,
"hoist": "all"
}
],
"no-warning-comments": 1,
"no-magic-numbers": [
1,
{
"ignore": [
-1,
0,
1,
2
]
}
],
"no-undefined": 0,
"operator-linebreak": [
2,
"after",
{
"overrides": {
":": "ignore"
}
}
],
"quotes": [
2,
"single",
"avoid-escape"
],
"quote-props": [
2,
"as-needed",
{
"keywords": false,
"numbers": false,
"unnecessary": false
}
],
"valid-jsdoc": [
2,
{
"matchDescription": "^[\\&\\w\\s/\\-\\.\\'\\,\\(\\)\\<\\>/]+$",
"prefer": {
"return": "returns"
},
"preferType": {},
"requireParamDescription": true,
"requireReturn": false,
"requireReturnDescription": true,
"requireReturnType": true
}
]
}
}
}
3 changes: 3 additions & 0 deletions res/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"SERVER_START": "Server started on port %{port}"
}
37 changes: 37 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const cookieParser = require('cookie-parser');
const express = require('express');
const log = require('./logging');
const path = require('path');


/* Create application */
const app = express();
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));


/* Server settings */
app.set('view engine', 'ejs');
app.set('port', process.env.port || 3000);
app.set('hostname', process.env.port || 'localhost');
app.set('protocol', process.env.protocol || 'http');


/* RunKeeper integration - details come from RunKeeper application portal */
app.set('client_id', process.env.client_id);
app.set('client_secret', process.env.client_secret);
app.set('authorization_url', process.env.authorization_url || 'https://runkeeper.com/apps/authorize');
app.set('token_url', process.env.token_url || 'https://runkeeper.com/apps/token');
app.set('redirect_uri', process.env.redirect_url || `${app.get('protocol')}://${app.get('hostname')}:${app.get('port')}/auth`);


/* Create routes */
require('./routes/auth')(app);
require('./routes/index')(app);
require('./routes/graphql')(app);


/* Start Application */
app.listen(app.get('port'), () => {
log.info('SERVER_START', { port: app.get('port') });
});
21 changes: 21 additions & 0 deletions src/data-types/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const graphql = require('graphql');
const GraphQLObjectType = graphql.GraphQLObjectType;
const GraphQLString = graphql.GraphQLString;
const GraphQLBoolean = graphql.GraphQLBoolean;

module.exports = new GraphQLObjectType({
name: 'Profile',
fields: {
name: { type: GraphQLString },
location: { type: GraphQLString },
athlete_type: { type: GraphQLString },
gender: { type: GraphQLString },
birthday: { type: GraphQLString },
elite: { type: GraphQLBoolean },
profile: { type: GraphQLString },
small_picture: { type: GraphQLString },
normal_picture: { type: GraphQLString },
medium_picture: { type: GraphQLString },
large_picture: { type: GraphQLString }
}
});
77 changes: 77 additions & 0 deletions src/data-types/strength-training-activities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const graphql = require('graphql');
const GraphQLObjectType = graphql.GraphQLObjectType;
const GraphQLString = graphql.GraphQLString;
const GraphQLList = graphql.GraphQLList;
const GraphQLInt = graphql.GraphQLInt;
const fetch = require('../helpers/fetch');

const StrengthTrainingSet = new GraphQLObjectType({
name: 'StrengthTrainingSet',
fields: {
weight: { type: GraphQLInt },
repetitions: { type: GraphQLInt },
notes: { type: GraphQLString}
}
});

const StrengthTrainingExercise = new GraphQLObjectType({
name: 'StrengthTrainingExercise',
fields: {
primary_type: { type: GraphQLString },
secondary_type: { type: GraphQLString },
primary_muscle_group: { type: GraphQLString },
secondary_muscle_group: { type: GraphQLString },
routine: { type: GraphQLString },
notes: { type: GraphQLString },
sets: { type: new GraphQLList(StrengthTrainingSet) }
}
});

const StrengthTrainingItem = new GraphQLObjectType({
name: 'StrengthTrainingItem',
fields: {
start_time: { type: GraphQLString },
uri: { type: GraphQLString },
userID: {
type: GraphQLString,
resolve (parent, args, req) {
return fetch(parent.uri, req).then(d => d.userID);
}
},
total_calories: {
type: GraphQLInt,
resolve (parent, args, req) {
return fetch(parent.uri, req).then(d => d.total_calories);
}
},
notes: {
type: GraphQLString,
resolve (parent, args, req) {
return fetch(parent.uri, req).then(d => d.notes);
}
},
source: {
type: GraphQLString,
resolve (parent, args, req) {
return fetch(parent.uri, req).then(d => d.source);
}
},
exercises: {
type: new GraphQLList(StrengthTrainingExercise),
resolve (parent, args, req) {
return fetch(parent.uri, req).then(d => d.exercises);
}
}
}
});


module.exports = new GraphQLObjectType({
name: 'StrengthTrainingActivities',
fields: {
size: { type: GraphQLInt },
items: {
type: new GraphQLList(StrengthTrainingItem)
}
}
});
28 changes: 28 additions & 0 deletions src/data-types/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const graphql = require('graphql');
const GraphQLObjectType = graphql.GraphQLObjectType;
const GraphQLString = graphql.GraphQLString;

const fetch = require('../helpers/fetch');
const ProfileType = require('./profile');
const StrengthTrainingActivitiesType = require('./strength-training-activities');

module.exports = new GraphQLObjectType({
name: 'User',
fields: {
userID: {
type: GraphQLString
},
profile: {
type: ProfileType,
resolve (data, args, req) {
return fetch(data.profile, req);
}
},
strength_training_activities: {
type: StrengthTrainingActivitiesType,
resolve (data, args, req) {
return fetch(data.strength_training_activities, req);
}
}
}
});
9 changes: 9 additions & 0 deletions src/helpers/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const request = require('superagent-promise')(require('superagent'), Promise);

module.exports = function fetch (endpoint, req) {
return request
.get(`https://api.runkeeper.com${endpoint}`)
.query({access_token: req.cookies.auth})
.end()
.then(data => data.body);
};
7 changes: 7 additions & 0 deletions src/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const Polyglot = require('node-polyglot');
const polyglot = new Polyglot();
const strings = require('../res/i18n/en.json');

polyglot.extend(strings);

module.exports = polyglot;
Loading

0 comments on commit aea4923

Please sign in to comment.