update logger

This commit is contained in:
Barry Low committed 2018-10-30 21:34:00 -07:00
1 parent 2449c642d2
commit 94c962cd44
12 files changed
+46 -29

No files matched your search

+9 -5
View File
@@ -3,9 +3,10 @@ import _get from 'lodash.get'
import { logger, AuthenticationError } from '../logger'
const memberLocationOnContext = 'request.user'
const userIdOnContext = 'req.userid'
const userIdOnContext = 'request.headers.userid'
const bearerAccessToken = 'request.headers.authorization'
const ctxUserId = ctx => _get(ctx, userIdOnContext)
const ctxMember = ctx => _get(ctx, memberLocationOnContext)
const ctxToken = ctx => _get(ctx, bearerAccessToken)
@@ -28,10 +29,12 @@ const createMember = async (ctx, idToken, info) => {
}
const isUserId = async ctx => {
logger.info(`isUserId 0: ${ctx.userId}`)
let member = ctxMember(ctx, userIdOnContext)
logger.info(`isUserId 0: ${ctx.request.headers.userid}`)
logger.info(`isUserId 1: ${ctx.request}`)
let member = await ctxUserId(ctx)
logger.info(member)
if (!member) {
throw new AuthenticationError('Access token is missing or expired')
throw new AuthenticationError()
} else {
return member
}
@@ -58,7 +61,8 @@ const assertAuth = ctx => {
export const directiveResolvers = {
isAuthenticated: async (next, source, args, ctx) => {
let result = await isUserId(ctx)
logger.info('directive isAuthenticated: ', result)
logger.info('directive isAuthenticated: ')
logger.info(await result)
return next(result)
},
hasRole: (next, source, { roles }, ctx) => {
+1 -1
View File
@@ -1,4 +1,4 @@
const gql = require('graphql-tag')
import gql from 'graphql-tag'
const TEAM_FB_FRAGMENT = gql`{
id
@@ -1,4 +1,4 @@
const gql = require('graphql-tag')
import gql from 'graphql-tag'
const TEAMS_CONNECTIONS_FRAGMENT = gql`{
edges {
+1 -1
View File
@@ -1,4 +1,4 @@
const gql = require('graphql-tag')
import gql from 'graphql-tag'
const TEAMS_FRAGMENT = gql`{
id
+5 -2
View File
@@ -1,6 +1,6 @@
import { getUser } from '../../../middleware/getMember'
import { sendTeamMemberInvite, sendTeamCreateConfirmation, verifyInviteToken } from '../../..//email/sendgrid'
import { sendTeamMemberInvite, sendTeamCreateConfirmation, verifyInviteToken } from '../../../email/sendgrid'
import TEAM_FB_FRAGMENT from '../../fragments/TeamFBFragment'
@@ -40,7 +40,10 @@ export const resolvers = {
logger.info('createTeam ctx.request.user:')
logger.info(ctx.request.user)
const authId = ctx.userId
const authId = ctx.request.headers.userid
if (!authId) {
throw new AuthenticationError()
}
return getUser(authId)
.then(async result => {
+7 -6
View File
@@ -1,12 +1,13 @@
import { logger, AuthentificationError, DatabaseError } from '../../../logger'
import { logger, AuthenticationError, DatabaseError } from '../../../logger'
export const member = async (parent, arg, ctx, info) => {
logger.info(ctx.request.userId, ' --> resolver.member')
const authId = ctx.request.userId
logger.info(' --> resolver.member')
logger.info(ctx.request)
const authId = ctx.request.headers.userid
if (!authId) {
throw new AuthentificationError()
throw new AuthenticationError()
}
return ctx.db.query.member({ where: { authId: arg.authId } }, info)
return ctx.db.query.member({ where: { authId } }, info)
.catch(err => {
logger.debug('resolver.member error: ')
logger.debug(err)
@@ -18,7 +19,7 @@ export const owner = async (parent, args, ctx, info) => {
logger.info('resolver.query.owner ctx: ')
const authId = ctx.request.userId
if (!authId) {
return throw new AuthentificationError()
throw new AuthenticationError()
}
return ctx.db.query.member({ where: { authId: authId } }, info)
.catch(err => {
+12 -6
View File
@@ -4,7 +4,8 @@ import TEAMS_CONNECTIONS_FRAGMENT from '../../fragments/TeamsConnectionsFragment
import TEAMS_FRAGMENT from '../../fragments/TeamsFragment'
export const teams = async (parent, args, ctx, info) => {
logger.info('teams: ', ctx.request.res)
logger.info('teams')
console.log('teams')
return ctx.db.query.teamsConnection({}, TEAMS_CONNECTIONS_FRAGMENT)
}
@@ -20,15 +21,20 @@ export const teamWithRole = async (parent, { teamId, role }, ctx, info) => {
return ctx.db.query.teamsConnection({where: {AND: [{id: teamId},{members_some:{role: role}}]}, first:1}, info)
}
export const teamsByOwner = async (parent, { ownerId }, ctx, info) => {
export const teamsByOwner = async (parent, args, ctx, info) => {
logger.info('teamsByOwner')
logger.info(ctx.req.headers)
logger.info(ctx.req.token)
return ctx.db.query.teams({where: { owner: ownerId }, orderBy:'updatedAt_DESC'}, TEAMS_FRAGMENT)
const authId = ctx.request.headers.userid
if (!authId) {
throw new AuthenticationError()
}
return ctx.db.query.teams({where: { owner: authId }, orderBy:'updatedAt_DESC'}, TEAMS_FRAGMENT)
}
export const teamsByRole = async (parent, args, ctx, info) => {
const authId = ctx.request.userId
const authId = ctx.request.headers.userid
if (!authId) {
throw new AuthenticationError()
}
let teamAdmin
try {
teamAdmin= await ctx.db.query.teams({where: {members_some: {AND: [{member: {authId: authId}, role_not:'MEMBER'}]}}}, TEAMS_FRAGMENT)
@@ -2,7 +2,10 @@ import { logger } from '../../../logger'
export const fbByTeamMember = async (parent, args, ctx, info) => {
logger.info('fbByTeamMember: ', args, ctx.request, ctx.request.res.req.user)
const authId = ctx.request.userId
const authId = ctx.request.headers.userid
if (!authId) {
throw new AuthenticationError()
}
let teamMemberFB = await ctx.db.query.teams({where: {members_some: {AND: [{member: {authId: authId}}]}}, orderBy: 'updatedAt_DESC'}, TEAM_FB_FRAGMENT)
logger.info('fbByTeamMember response: ', await teamMemberFB[0])
return teamMemberFB[0]
+1 -1
View File
@@ -3,4 +3,4 @@ import merge from 'lodash.merge'
import { resolvers as queryResolvers } from './Query'
import { resolvers as mutationResolvers } from './Mutation'
const resolvers = merge(queryResolvers, mutationResolvers)
export const resolvers = merge(queryResolvers, mutationResolvers)
+1 -1
View File
@@ -11,7 +11,7 @@ type Query {
teamByName(name: String!): Team
teamById(teamId: String!): Team
teamWithRole(teamId: String!, role: String!): Team
teamsByOwner(ownerId: String!): [Team!]! @isAuthenticated
teamsByOwner: [Team!]! @isAuthenticated
teamsByRole: [Team!]! @isAuthenticated
fbByTeamMember: Team @isAuthenticated
owner: Member @isAuthenticated
+1 -1
View File
@@ -64,7 +64,7 @@ const server = createApolloServer(app, {
...req ,
token: req.headers ? req.headers : undefined,
user: req.user ? req.user : undefined,
userId: null,
userId: (req.headers && req.headers.userid) ? req.headers.userid : undefined,
db,
pubsub
})
+3 -3
View File
@@ -1,11 +1,11 @@
export class AuthentificationError extends Error {
export class AuthenticationError extends Error {
code = 401
message = 'Autentification not found, you have to be authentificated to perform this action'
message = 'Not Authenticated - you have to be authenticated to perform this action'
}
export class DatabaseError extends Error {
code = 404
message = 'Ressource not found : ' + this.message
message = 'Resource not found : ' + this.message
}
export class WrongArgumentsError extends Error {