Skip to content

Commit

Permalink
update for optimization and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jhk482001 committed Feb 10, 2025
1 parent ca9c1ee commit 06793bf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 30 deletions.
8 changes: 0 additions & 8 deletions src/adm/handlers/moderation/__tests__/awardBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ describe('awardBadge', () => {
);
});

/**
* Asserts the document in database is the same as in the fixture,
* i.e. the document is not modified
*
* @param {string} fixtureKey
* @param {{index: string; id: string;}} clientGetArgs - Arguments for client.get()
*/

it('correctly sets the awarded badge id when authorized', async () => {
const result = await awardBadge({
userId: 'user-to-award-badge',
Expand Down
5 changes: 0 additions & 5 deletions src/graphql/dataLoaders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import repliedArticleCountLoaderFactory from './repliedArticleCountLoaderFactory
import votedArticleReplyCountLoaderFactory from './votedArticleReplyCountLoaderFactory';
import userLevelLoaderFactory from './userLevelLoaderFactory';
import userLoaderFactory from './userLoaderFactory';
import badgeLoaderFactory from './badgeLoaderFactory';
import contributionsLoaderFactory from './contributionsLoaderFactory';

const LOADER_FACTORY_MAP = {
Expand All @@ -25,7 +24,6 @@ const LOADER_FACTORY_MAP = {
repliedArticleCountLoader: repliedArticleCountLoaderFactory,
votedArticleReplyCountLoader: votedArticleReplyCountLoaderFactory,
userLoader: userLoaderFactory,
badgeLoader: badgeLoaderFactory,
userLevelLoader: userLevelLoaderFactory,
analyticsLoader: analyticsLoaderFactory,
contributionsLoader: contributionsLoaderFactory,
Expand Down Expand Up @@ -66,9 +64,6 @@ export default class DataLoaders {
get userLoader() {
return this._checkOrSetLoader('userLoader');
}
get badgeLoader() {
return this._checkOrSetLoader('badgeLoader');
}
get userLevelLoader() {
return this._checkOrSetLoader('userLevelLoader');
}
Expand Down
16 changes: 8 additions & 8 deletions src/graphql/models/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { GraphQLObjectType, GraphQLString } from 'graphql';
export default new GraphQLObjectType({
name: 'Badge',
fields: () => ({
name: { type: GraphQLString },
displayName: { type: GraphQLString },
description: { type: GraphQLString },
link: { type: GraphQLString },
icon: { type: GraphQLString },
borderImage: { type: GraphQLString },
issuers: { type: GraphQLString },
createdAt: { type: GraphQLString },
name: { type: new GraphQLNonNull(GraphQLString) },

Check failure on line 6 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined

Check failure on line 6 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined
displayName: { type: new GraphQLNonNull(GraphQLString) },

Check failure on line 7 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined

Check failure on line 7 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined
description: { type: new GraphQLNonNull(GraphQLString) },

Check failure on line 8 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined

Check failure on line 8 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined
link: { type: new GraphQLNonNull(GraphQLString) },

Check failure on line 9 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined

Check failure on line 9 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined
icon: { type: new GraphQLNonNull(GraphQLString) },

Check failure on line 10 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined

Check failure on line 10 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined
borderImage: { type: new GraphQLNonNull(GraphQLString) },

Check failure on line 11 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined

Check failure on line 11 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined
issuers: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))) },

Check failure on line 12 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

Replace `·type:·new·GraphQLNonNull(new·GraphQLList(new·GraphQLNonNull(GraphQLString)))` with `⏎······type:·new·GraphQLNonNull(⏎········new·GraphQLList(new·GraphQLNonNull(GraphQLString))⏎······),⏎···`

Check failure on line 12 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined

Check failure on line 12 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLList' is not defined

Check failure on line 12 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined

Check failure on line 12 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

Replace `·type:·new·GraphQLNonNull(new·GraphQLList(new·GraphQLNonNull(GraphQLString)))` with `⏎······type:·new·GraphQLNonNull(⏎········new·GraphQLList(new·GraphQLNonNull(GraphQLString))⏎······),⏎···`

Check failure on line 12 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined

Check failure on line 12 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLList' is not defined

Check failure on line 12 in src/graphql/models/Badge.js

View workflow job for this annotation

GitHub Actions / install-and-test

'GraphQLNonNull' is not defined
createdAt: { type: new GraphQLNonNull(GraphQLString) },
updatedAt: { type: GraphQLString },
}),
});
8 changes: 4 additions & 4 deletions src/graphql/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ const User = new GraphQLObjectType({
},

badges: {
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(Badge))),
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, atgs, { loaders }) => {
resolve: async (user, args, { loaders }) => {
const displayItem = user.badges.find({ isDisplay: true });
if (displayItem == null) {
return null;
Expand All @@ -186,7 +186,7 @@ const User = new GraphQLObjectType({
majorBadgeImageUrl: {
type: GraphQLString,
description: 'returns badge background image url',
resolve: async (user, atgs, { loaders }) => {
resolve: async (user, args, { loaders }) => {
const displayItem = user.badges.find({ isDisplay: true });
if (displayItem == null) {
return null;
Expand All @@ -203,7 +203,7 @@ const User = new GraphQLObjectType({
majorBadgeName: {
type: GraphQLString,
description: 'returns badge background image url',
resolve: async (user, atgs, { loaders }) => {
resolve: async (user, args, { loaders }) => {
const displayItem = user.badges.find({ isDisplay: true });
if (displayItem == null) {
return null;
Expand Down
10 changes: 5 additions & 5 deletions src/graphql/models/UserAwardedBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { GraphQLBoolean, GraphQLObjectType, GraphQLString } from 'graphql';
export default new GraphQLObjectType({
name: 'UserAwardedBadge',
fields: () => ({
badgeId: { type: GraphQLString },
badgeMetaData: { type: GraphQLString },
isDisplayed: { type: GraphQLBoolean },
createdAt: { type: GraphQLString },
updatedAt: { type: GraphQLString },
badgeId: { type: new GraphQLNonNull(GraphQLString) },
badgeMetaData: { type: new GraphQLNonNull(GraphQLString) },
isDisplayed: { type: new GraphQLNonNull(GraphQLBoolean) },
createdAt: { type: new GraphQLNonNull(GraphQLString) },
updatedAt: { type: new GraphQLNonNull(GraphQLString) },
}),
});

0 comments on commit 06793bf

Please sign in to comment.