From 4734a72c138267670fd3c0ee9d368222d5b20693 Mon Sep 17 00:00:00 2001 From: carrick Date: Thu, 29 Feb 2024 13:22:44 +0900 Subject: [PATCH] refactor: postService to include IP address in write and edit methods --- src/graphql/post.ts | 4 ++-- src/services/postService.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/graphql/post.ts b/src/graphql/post.ts index 57ba1c5..0cba179 100644 --- a/src/graphql/post.ts +++ b/src/graphql/post.ts @@ -646,10 +646,10 @@ export const resolvers: IResolvers = { }, Mutation: { writePost: async (parent: any, args, ctx) => { - return await postService.write(args, ctx.cookies); + return await postService.write(args, ctx.cookies, ctx.ip); }, editPost: async (parent: any, args, ctx) => { - return await postService.edit(args, ctx.cookies); + return await postService.edit(args, ctx.cookies, ctx.ip); }, removePost: async (parent: any, args, ctx) => { const { id } = args as { id: string }; diff --git a/src/services/postService.ts b/src/services/postService.ts index 37c7ef4..8b0edfa 100644 --- a/src/services/postService.ts +++ b/src/services/postService.ts @@ -322,7 +322,7 @@ const postService = { } }, - async write(args: WritePostArgs, cookies: Cookies) { + async write(args: WritePostArgs, cookies: Cookies, ip: string) { const WRITE_POST_MUTATION = ` mutation WritePost($input: WritePostInput!) { writePost(input: $input) { @@ -355,6 +355,7 @@ const postService = { headers: { 'Content-Type': 'application/json', authorization: `Bearer ${accessToken}`, + 'X-Forwarded-For': ip, }, } ); @@ -364,7 +365,7 @@ const postService = { console.log('write post error', error); } }, - async edit(args: EditPostArgs, cookies: Cookies) { + async edit(args: EditPostArgs, cookies: Cookies, ip: string) { const EDIT_POST_MUTATION = ` mutation EditPost($input: EditPostInput!) { editPost(input: $input) { @@ -396,6 +397,7 @@ const postService = { headers: { 'Content-Type': 'application/json', authorization: `Bearer ${accessToken}`, + 'X-Forwarded-For': ip, }, } );