Skip to content

Commit 8063f10

Browse files
authored
Merge pull request #169 from velopert/fix/post-api
refactor: postService to include IP address in write and edit methods
2 parents d34088b + 4734a72 commit 8063f10

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/graphql/post.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,10 @@ export const resolvers: IResolvers<any, ApolloContext> = {
646646
},
647647
Mutation: {
648648
writePost: async (parent: any, args, ctx) => {
649-
return await postService.write(args, ctx.cookies);
649+
return await postService.write(args, ctx.cookies, ctx.ip);
650650
},
651651
editPost: async (parent: any, args, ctx) => {
652-
return await postService.edit(args, ctx.cookies);
652+
return await postService.edit(args, ctx.cookies, ctx.ip);
653653
},
654654
removePost: async (parent: any, args, ctx) => {
655655
const { id } = args as { id: string };

src/services/postService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ const postService = {
322322
}
323323
},
324324

325-
async write(args: WritePostArgs, cookies: Cookies) {
325+
async write(args: WritePostArgs, cookies: Cookies, ip: string) {
326326
const WRITE_POST_MUTATION = `
327327
mutation WritePost($input: WritePostInput!) {
328328
writePost(input: $input) {
@@ -355,6 +355,7 @@ const postService = {
355355
headers: {
356356
'Content-Type': 'application/json',
357357
authorization: `Bearer ${accessToken}`,
358+
'X-Forwarded-For': ip,
358359
},
359360
}
360361
);
@@ -364,7 +365,7 @@ const postService = {
364365
console.log('write post error', error);
365366
}
366367
},
367-
async edit(args: EditPostArgs, cookies: Cookies) {
368+
async edit(args: EditPostArgs, cookies: Cookies, ip: string) {
368369
const EDIT_POST_MUTATION = `
369370
mutation EditPost($input: EditPostInput!) {
370371
editPost(input: $input) {
@@ -396,6 +397,7 @@ const postService = {
396397
headers: {
397398
'Content-Type': 'application/json',
398399
authorization: `Bearer ${accessToken}`,
400+
'X-Forwarded-For': ip,
399401
},
400402
}
401403
);

0 commit comments

Comments
 (0)