From 0317b0cd06c62176a63fa088be3d6dd2aedfeb26 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 23 Oct 2018 15:30:46 +0200 Subject: [PATCH] Fixes #7 --- client/components/ProfileSheet.js | 1 - client/components/YourReferrer.js | 1 - client/config/logger.js | 39 +++++++++++++++++++++++++++++++ client/queries/queries.js | 26 ++------------------- server/schema/schema.js | 30 ++++-------------------- 5 files changed, 45 insertions(+), 52 deletions(-) create mode 100644 client/config/logger.js diff --git a/client/components/ProfileSheet.js b/client/components/ProfileSheet.js index 56a4dd74e..1d81a4368 100644 --- a/client/components/ProfileSheet.js +++ b/client/components/ProfileSheet.js @@ -108,7 +108,6 @@ class ProfileSheet extends Component { e.preventDefault() this.props.updateUserMutation({ variables: { - id: this.state.id, firstName: this.state.firstName, middleName: this.state.middleName, lastName: this.state.lastName, diff --git a/client/components/YourReferrer.js b/client/components/YourReferrer.js index 946f2e4e7..6a658ea4d 100644 --- a/client/components/YourReferrer.js +++ b/client/components/YourReferrer.js @@ -60,7 +60,6 @@ class YourReferrer extends Component { this.props.updateReferrerMutation({ variables: { - id: this.state.id, referrerId: referrerUser.id } }) diff --git a/client/config/logger.js b/client/config/logger.js new file mode 100644 index 000000000..bc16b3ddc --- /dev/null +++ b/client/config/logger.js @@ -0,0 +1,39 @@ +const { createLogger, format, transports } = require('winston') +const { combine, timestamp, simple } = format + +const options = { + file: { + level: 'info', + filename: '../logs/app.log', + handleExceptions: true, + json: true, + maxsize: 5242880, // 5MB + maxFiles: 5, + colorize: false, + timestamp: true + }, + console: { + level: 'debug', + handleExceptions: true, + json: false, + colorize: true, + timestamp: true + } +} + +const logger = createLogger({ + level: 'info', + format: combine( + timestamp({ + format: 'YYYY-MM-DD HH:mm:ss' + }), + simple() + ), + transports: [ + new transports.File(options.file), + new transports.Console(options.console) + ], + exitOnError: false // do not exit on handled exceptions +}) + +module.exports = logger diff --git a/client/queries/queries.js b/client/queries/queries.js index 841538779..8a58b3d04 100644 --- a/client/queries/queries.js +++ b/client/queries/queries.js @@ -112,7 +112,6 @@ const getRolesQuery = gql` ` const updateUserMutation = gql` mutation( - $id: ID!, $firstName:String, $middleName:String, $lastName:String, @@ -124,7 +123,6 @@ mutation( ) { users_UpdateUser ( - id: $id, firstName:$firstName, middleName: $middleName, lastName: $lastName, @@ -142,12 +140,10 @@ mutation( ` const updateReferrerMutation = gql` mutation( - $id: ID!, $referrerId:String! ) { users_UpdateUserReferrer ( - id: $id, referrerId:$referrerId ) { @@ -156,24 +152,7 @@ mutation( } } ` -const updateUserImagesMutation = gql` -mutation( - $id: ID!, - $avatarHandle:String, - $avatarChangeDate:String -) - { - users_UpdateUserImages ( - id: $id, - avatarHandle:$avatarHandle, - avatarChangeDate: $avatarChangeDate - ) - { - id - alias - } -} -` + export { getUsersQuery, getUserByAuthIdQuery, @@ -182,6 +161,5 @@ export { getUsersBySearchFields, getDescendentsQuery, updateUserMutation, - updateReferrerMutation, - updateUserImagesMutation + updateReferrerMutation } diff --git a/server/schema/schema.js b/server/schema/schema.js index 21de4633b..b3495821f 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -218,7 +218,6 @@ const Mutation = new GraphQLObjectType({ updateUser: { type: UserType, args: { - id: {type: new GraphQLNonNull(GraphQLID)}, firstName: {type: GraphQLString}, middleName: {type: GraphQLString}, lastName: {type: GraphQLString}, @@ -228,9 +227,9 @@ const Mutation = new GraphQLObjectType({ isDataAnalyst: {type: GraphQLInt}, roleId: {type: new GraphQLNonNull(GraphQLString)} }, - resolve (parent, args) { + resolve (parent, args, context) { let key = { - _id: args.id + _id: context.userId } let updatedUser = { @@ -247,35 +246,14 @@ const Mutation = new GraphQLObjectType({ return User.update(key, updatedUser) } }, - updateUserImages: { - type: UserType, - args: { - id: {type: new GraphQLNonNull(GraphQLID)}, - avatarHandle: {type: GraphQLString}, - avatarChangeDate: {type: GraphQLString} - }, - resolve (parent, args) { - let key = { - _id: args.id - } - - let updatedUser = { - avatarHandle: args.avatarHandle, - avatarChangeDate: args.avatarChangeDate - } - - return User.update(key, updatedUser) - } - }, updateUserReferrer: { type: UserType, args: { - id: {type: new GraphQLNonNull(GraphQLID)}, referrerId: {type: GraphQLString} }, - resolve (parent, args) { + resolve (parent, args, context) { let key = { - _id: args.id, + _id: context.userId, referrerId: null }