-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add Badge api #357
base: master
Are you sure you want to change the base?
add Badge api #357
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bdaae4f
to
8431d58
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to putMapping
in rumors-api
. I have already re-indexed Elasticsearch DB on staging and production with the latest schema (by running npm run reload
defined in rumors-db), so the users
index already have badges
field defined.
|
||
/* istanbul ignore if */ | ||
if (setbadgeIdResult === 'noop') { | ||
console.log(`Info: user ID ${userId} already has set the same badgeId.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the script above do not check if the same badge has been awarded or not, and always performs ctx._source.badges.add
.
In this case, this console.log
here would never be executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this unused loader implementation
badges: { | ||
type: new GraphQLNonNull( | ||
new GraphQLList(new GraphQLNonNull(UserAwardedBadge)) | ||
), | ||
description: 'Badges awarded to the user.', | ||
resolve: (user) => user.badges || [], | ||
}, | ||
|
||
majorBadgeBorderUrl: { | ||
type: GraphQLString, | ||
description: 'returns badge background image url', | ||
resolve: async (user, args, { loaders }) => { | ||
const displayItem = user.badges.find({ isDisplay: true }); | ||
if (displayItem == null) { | ||
return null; | ||
} | ||
const badgeId = displayItem.id; | ||
const badgeInfo = loaders.docLoader.load({ | ||
index: 'badges', | ||
id: badgeId, | ||
}); | ||
return badgeInfo.borderImage; | ||
}, | ||
}, | ||
|
||
majorBadgeImageUrl: { | ||
type: GraphQLString, | ||
description: 'returns badge background image url', | ||
resolve: async (user, args, { loaders }) => { | ||
const displayItem = user.badges.find({ isDisplay: true }); | ||
if (displayItem == null) { | ||
return null; | ||
} | ||
const badgeId = displayItem.id; | ||
const badgeInfo = loaders.docLoader.load({ | ||
index: 'badges', | ||
id: badgeId, | ||
}); | ||
return badgeInfo.icon; | ||
}, | ||
}, | ||
|
||
majorBadgeName: { | ||
type: GraphQLString, | ||
description: 'returns badge background image url', | ||
resolve: async (user, args, { loaders }) => { | ||
const displayItem = user.badges.find({ isDisplay: true }); | ||
if (displayItem == null) { | ||
return null; | ||
} | ||
const badgeId = displayItem.id; | ||
const badgeInfo = loaders.docLoader.load({ | ||
index: 'badges', | ||
id: badgeId, | ||
}); | ||
return badgeInfo.name; | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is recommended that we add a unit test (and relevant fixtures) under https://github.com/cofacts/rumors-api/blob/master/src/graphql/queries/__tests__/GetUser.js to ensure that these newly added fields can be loaded as expected.
@@ -39,7 +39,7 @@ services: | |||
ELASTICSEARCH_URL: "http://db:9200" | |||
URL_RESOLVER_URL: "url-resolver:4000" | |||
ports: | |||
- "5000:5000" | |||
- "6000:5000" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to ask: what is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should revert this one, I found that Mac default use 5000 port for airplay receiver
git add . ; exit exit()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not appear in the schema because this new query is not included in graphql/schema.js
No description provided.