Skip to content

Commit ca7dc53

Browse files
committed
Created utility functions
1 parent 9f43d90 commit ca7dc53

File tree

4 files changed

+76
-71
lines changed

4 files changed

+76
-71
lines changed

src/services/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import apiCall from './api'
2-
import { BASIC_STORY_INFO_FRAGMENT } from './gql_fragments'
2+
import { BASIC_STORY_INFO_FRAGMENT } from './utils/gql_fragments'
33

44
const User = {
55
updateUser: (user) => {

src/services/user_story.js

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import apiCall from './api'
2+
import { getUserStoryQuery } from './utils/getUserStoryQuery'
23
import {
34
BASIC_STORY_INFO_FRAGMENT,
45
NOTIFICATION_DATA_FRAGMENT
5-
} from './gql_fragments'
6+
} from './utils/gql_fragments'
67

78
const userStory = {
89
createStory: ({ description, title, category, product, priority }) => {
@@ -46,76 +47,9 @@ const userStory = {
4647
}
4748
return apiCall('/graphql', query)
4849
},
49-
getStories: ({
50-
sortBy = 'createdAt:desc',
51-
limit = null,
52-
page = null,
53-
currentStateSelected = '',
54-
authorId = '',
55-
authorQuery = '',
56-
categoryQuery = '',
57-
productQuery = '',
58-
searchQuery = '',
59-
followers = ''
60-
}) => {
61-
page = !page || !limit ? '' : `start: ${(page - 1) * limit}`
62-
63-
limit = !limit ? '' : `limit: ${limit}`
64-
65-
currentStateSelected =
66-
currentStateSelected === ''
67-
? ''
68-
: `user_story_status : {
69-
Status: "${currentStateSelected}"
70-
}`
71-
72-
authorId = authorId === '' ? '' : `id: "${authorId}"`
73-
74-
authorQuery =
75-
authorQuery === '' ? '' : `username_contains: "${authorQuery}"`
76-
77-
followers = followers === '' ? '' : `followers: "${followers}"`
78-
50+
getStories: (filters) => {
7951
const storiesQuery = {
80-
query: `query {
81-
userStories(
82-
sort: "${sortBy}"
83-
${limit}
84-
${page}
85-
where: {
86-
author: {
87-
${authorId}
88-
${authorQuery}
89-
}
90-
${followers}
91-
${currentStateSelected}
92-
${categoryQuery}
93-
${productQuery}
94-
${searchQuery}
95-
}) {
96-
...BasicStoryInfo
97-
user_story_status {
98-
Status
99-
}
100-
user_story_comments {
101-
Comments
102-
}
103-
product {
104-
Name
105-
}
106-
author {
107-
id
108-
username
109-
profilePicture {
110-
id
111-
url
112-
}
113-
}
114-
Category
115-
}
116-
}
117-
${BASIC_STORY_INFO_FRAGMENT}
118-
`
52+
query: getUserStoryQuery(filters)
11953
}
12054
return apiCall('/graphql', storiesQuery)
12155
},
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { BASIC_STORY_INFO_FRAGMENT } from './gql_fragments'
2+
3+
export const getUserStoryQuery = ({
4+
sortBy = 'createdAt:desc',
5+
limit = null,
6+
page = null,
7+
currentStateSelected = '',
8+
authorId = '',
9+
authorQuery = '',
10+
categoryQuery = '',
11+
productQuery = '',
12+
searchQuery = '',
13+
followers = ''
14+
}) => {
15+
page = !page || !limit ? '' : `start: ${(page - 1) * limit}`
16+
17+
limit = !limit ? '' : `limit: ${limit}`
18+
19+
currentStateSelected =
20+
currentStateSelected === ''
21+
? ''
22+
: `user_story_status : {
23+
Status: "${currentStateSelected}"
24+
}`
25+
26+
authorId = authorId === '' ? '' : `id: "${authorId}"`
27+
28+
authorQuery = authorQuery === '' ? '' : `username_contains: "${authorQuery}"`
29+
30+
followers = followers === '' ? '' : `followers: "${followers}"`
31+
32+
return `query {
33+
userStories(
34+
sort: "${sortBy}"
35+
${limit}
36+
${page}
37+
where: {
38+
author: {
39+
${authorId}
40+
${authorQuery}
41+
}
42+
${followers}
43+
${currentStateSelected}
44+
${categoryQuery}
45+
${productQuery}
46+
${searchQuery}
47+
}) {
48+
...BasicStoryInfo
49+
user_story_status {
50+
Status
51+
}
52+
user_story_comments {
53+
Comments
54+
}
55+
product {
56+
Name
57+
}
58+
author {
59+
id
60+
username
61+
profilePicture {
62+
id
63+
url
64+
}
65+
}
66+
Category
67+
}
68+
}
69+
${BASIC_STORY_INFO_FRAGMENT}
70+
`
71+
}
File renamed without changes.

0 commit comments

Comments
 (0)