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

Commit

Permalink
refactor(*): Refactor data type stucture
Browse files Browse the repository at this point in the history
Refactored data-types to be easier to manage
  • Loading branch information
Simon Wears committed Mar 25, 2017
1 parent 4024d15 commit 5f91364
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 224 deletions.
137 changes: 0 additions & 137 deletions src/data-types/strength-training-activities.js

This file was deleted.

23 changes: 23 additions & 0 deletions src/data-types/strength-training/activities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const graphql = require('graphql');
const GraphQLObjectType = graphql.GraphQLObjectType;
const GraphQLList = graphql.GraphQLList;
const GraphQLInt = graphql.GraphQLInt;
const resolveItems = require('../../helpers/resolve-items');
const i18n = require('../../helpers/i18n');
const StrengthTrainingItem = require('./item');

module.exports = new GraphQLObjectType({
name: 'StrengthTrainingActivities',
fields: {
size: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.ACTIVITIES.SIZE'),
type: GraphQLInt
},
items: {
args: resolveItems.args,
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.ACTIVITIES.ITEMS'),
resolve: resolveItems.resolve,
type: new GraphQLList(StrengthTrainingItem)
}
}
});
53 changes: 53 additions & 0 deletions src/data-types/strength-training/exercise-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const graphql = require('graphql');
const GraphQLEnumType = graphql.GraphQLEnumType;

module.exports = new GraphQLEnumType({
name: 'ExerciseTypes',
values: {
BARBELL_CURL: {value: 'Barbell Curl'},
DUMBBELL_CURL: {value: 'Dumbbell Curl'},
BARBELL_TRICEP_PRESS: {value: 'Barbell Tricep Press'},
DUMBBELL_TRICEP_PRESS: {value: 'Dumbbell Tricep Press'},
OVERHEAD_PRESS: {value: 'Overhead Press'},
WRIST_CURL: {value: 'Wrist Curl'},
TRICEP_KICKBACK: {value: 'Tricep Kickback'},
BENCH_PRESS: {value: 'Bench Press'},
CABLE_CROSSOVER: {value: 'Cable Crossover'},
DUBBELL_FLY: {value: 'Dumbbell Fly'},
INCLINE_BENCH: {value: 'Incline Bench'},
DIPS: {value: 'Dips'},
PUSHUP: {value: 'Pushup'},
PULLUP: {value: 'Pullup'},
BACK_RAISE: {value: 'Back Raise'},
BENT_OVER_ROW: {value: 'Bent-Over Row'},
SEATED_ROW: {value: 'Seated Row'},
CHINUP: {value: 'Chinup'},
LAT_PULLDOWN: {value: 'Lat Pulldown'},
SEATED_REVERSE_FLY: {value: 'Seated Reverse Fly'},
MILITARY_PRESS: {value: 'Military Press'},
UPRIGHT_ROW: {value: 'Upright Row'},
FRONT_RAISE: {value: 'Front Raise'},
SIDE_LATERAL_RAISE: {value: 'Side Lateral Raise'},
SNATCH: {value: 'Snatch'},
PUSH_PRESS: {value: 'Push Press'},
SHRUG: {value: 'Shrug'},
CRUNCH_MACHINE: {value: 'Crunch Machine'},
CRUNCH: {value: 'Crunch'},
AB_TWIST: {value: 'Ab Twist'},
BICYCLE_KICK: {value: 'Bicycle Kick'},
HANGING_LEG_RAISE: {value: 'Hanging Leg Raise'},
HANGING_KNEE_RAISE: {value: 'Hanging Knee Raise'},
REVERSE_CRUNCH: {value: 'Reverse Crunch'},
V_UP: {value: 'V Up'},
SITUP: {value: 'Situp'},
SQUAT: {value: 'Squat'},
LUNGE: {value: 'Lunge'},
DEAD_LIFT: {value: 'Dead Lift'},
HAMSTRING_CURL: {value: 'Hamstring Curl'},
GOOD_MORNING: {value: 'Good Morning'},
CLEAN: {value: 'Clean'},
LEG_PRESS: {value: 'Leg Press'},
LEG_EXTENSION: {value: 'Leg Extension'},
OTHER: {value: 'Other'}
}
});
40 changes: 40 additions & 0 deletions src/data-types/strength-training/exercise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const graphql = require('graphql');
const GraphQLString = graphql.GraphQLString;
const GraphQLList = graphql.GraphQLList;
const GraphQLObjectType = graphql.GraphQLObjectType;
const StrengthTrainingSet = require('./set');
const i18n = require('../../helpers/i18n');

module.exports = new GraphQLObjectType({
name: 'StrengthTrainingExercise',
fields: {
notes: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.EXERCISE.NOTES'),
type: GraphQLString
},
primary_muscle_group: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.EXERCISE.PRIMARY_MUSCLE_GROUP'),
type: GraphQLString
},
primary_type: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.EXERCISE.PRIMARY_TYPE'),
type: GraphQLString
},
routine: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.EXERCISE.ROUTINE'),
type: GraphQLString
},
secondary_muscle_group: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.EXERCISE.SECONDARY_MUSCLE_GROUP'),
type: GraphQLString
},
secondary_type: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.EXERCISE.SECONDARY_TYPE'),
type: GraphQLString
},
sets: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.EXERCISE.SETS'),
type: new GraphQLList(StrengthTrainingSet)
}
}
});
63 changes: 63 additions & 0 deletions src/data-types/strength-training/item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const graphql = require('graphql');
const GraphQLString = graphql.GraphQLString;
const GraphQLList = graphql.GraphQLList;
const GraphQLInt = graphql.GraphQLInt;
const GraphQLFloat = graphql.GraphQLFloat;
const GraphQLObjectType = graphql.GraphQLObjectType;
const StrengthTrainingExercise = require('./exercise');
const CommentType = require('../comment');
const i18n = require('../../helpers/i18n');

module.exports = new GraphQLObjectType({
name: 'StrengthTrainingItem',
fields: {
comments: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.ITEM.COMMENTS'),
resolve (parent, args, context) {
return context.healthGraphLoader.load(parent.uri)
.then(d => context.healthGraphLoader.load(d.comments))
.then(c => c.comments);
},
type: new GraphQLList(CommentType)
},
exercises: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.ITEM.EXERCISES'),
resolve (parent, args, context) {
return context.healthGraphLoader.load(parent.uri).then(d => d.exercises);
},
type: new GraphQLList(StrengthTrainingExercise)
},
notes: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.ITEM.NOTES'),
resolve (parent, args, context) {
return context.healthGraphLoader.load(parent.uri).then(d => d.notes);
},
type: GraphQLString
},
source: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.ITEM.SOURCE'),
resolve (parent, args, context) {
return context.healthGraphLoader.load(parent.uri).then(d => d.source);
},
type: GraphQLString
},
start_time: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.ITEM.START_TIME'),
type: GraphQLString
},
total_calories: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.ITEM.TOTAL_CALORIES'),
resolve (parent, args, context) {
return context.healthGraphLoader.load(parent.uri).then(d => d.total_calories);
},
type: GraphQLFloat
},
userID: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.ITEM.USERID'),
resolve (parent, args, context) {
return context.healthGraphLoader.load(parent.uri).then(d => d.userID);
},
type: GraphQLInt
}
}
});
14 changes: 14 additions & 0 deletions src/data-types/strength-training/muscle-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const graphql = require('graphql');
const GraphQLEnumType = graphql.GraphQLEnumType;

module.exports = new GraphQLEnumType({
name: 'MuscleTypes',
values: {
ABS: {value: 'Abs'},
ARMS: {value: 'Arms'},
BACK: {value: 'Back'},
CHEST: {value: 'Chest'},
LEGS: {value: 'Legs'},
SHOULDERS: {value: 'Shoulders'}
}
});
24 changes: 24 additions & 0 deletions src/data-types/strength-training/set.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const graphql = require('graphql');
const GraphQLString = graphql.GraphQLString;
const GraphQLInt = graphql.GraphQLInt;
const GraphQLFloat = graphql.GraphQLFloat;
const GraphQLObjectType = graphql.GraphQLObjectType;
const i18n = require('../../helpers/i18n');

module.exports = new GraphQLObjectType({
name: 'StrengthTrainingSet',
fields: {
notes: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.SET.NOTES'),
type: GraphQLString
},
repetitions: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.SET.REPETITIONS'),
type: GraphQLInt
},
weight: {
description: i18n.t('GRAPHQL.STRENGTH_TRAINING.SET.WEIGHT'),
type: GraphQLFloat
}
}
});
2 changes: 1 addition & 1 deletion src/data-types/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const GraphQLString = graphql.GraphQLString;
const i18n = require('../helpers/i18n');
const HEALTHGRAPH = require('../constants/healthgraph');
const ProfileType = require('./profile');
const StrengthTrainingActivitiesType = require('./strength-training-activities').StrengthTrainingActivities;
const StrengthTrainingActivitiesType = require('./strength-training/activities');
const FitnessActivitiesType = require('./fitness-activities').FitnessActivities;

module.exports = new GraphQLObjectType({
Expand Down
Loading

0 comments on commit 5f91364

Please sign in to comment.