Skip to content

Commit

Permalink
Merge pull request #19 from the-hideout/itemsbyids-query
Browse files Browse the repository at this point in the history
Adds itemsByIDs query.
  • Loading branch information
austinhodak authored Apr 5, 2022
2 parents ed4826d + 51d08a4 commit b1423f4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions datasources/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ class ItemsAPI {
return this.formatItem(item);
}

getItemsByIDs(ids) {
return Object.values(this.itemCache)
.filter((rawItem) => {
return ids.includes(rawItem.id);
})
.map((rawItem) => {
return this.formatItem(rawItem);
});
}

getItemsByType(type) {
return Object.values(this.itemCache)
.filter((rawItem) => {
Expand All @@ -194,6 +204,18 @@ class ItemsAPI {
});
}

getItemsByNames(names) {
const searchString = name.toLowerCase();

return Object.values(this.itemCache)
.filter((rawItem) => {
return rawItem.name.toLowerCase().includes(searchString) || rawItem.shortname.toLowerCase().includes(searchString);
})
.map((rawItem) => {
return this.formatItem(rawItem);
});
}

getItemsByBsgCategoryId(bsgCategoryId) {
return Object.values(this.itemCache)
.filter((rawItem) => {
Expand Down
4 changes: 4 additions & 0 deletions resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ module.exports = {
return await itemsAPI.getItem(args.id);
},

itemsByIDs: async (args) => {
return await itemsAPI.getItemsByIDs(args.ids)
},

itemsByType: async(args) => {
return await itemsAPI.getItemsByType(args.type);
},
Expand Down
1 change: 1 addition & 0 deletions schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ module.exports = `
type Query {
item(id: ID!): Item
itemsByIDs(ids: [ID]!): [Item]
itemsByType(type: ItemType!): [Item]!
itemsByName(name: String!): [Item]!
itemByNormalizedName(normalizedName: String!): Item
Expand Down

0 comments on commit b1423f4

Please sign in to comment.