Skip to content

Commit

Permalink
Change Query to Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
demariadaniel committed Nov 20, 2023
1 parent 8af705e commit 821fde1
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/schemas/Program/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,7 @@ const typeDefs = gql`
"""
retrieve all Programs
"""
programs: [Program]
"""
retrieve all Programs for a given region
"""
programsByDataCenter(shortName: String!): [Program]
programs(dataCenter: String): [Program]
"""
retrieve join program invitation by id
Expand Down Expand Up @@ -356,19 +351,14 @@ const resolvers = {
: resolvePublicSingleProgram(shortName);
},

programs: async (obj, args, context, info) => {
programs: async (obj, args, context) => {
const { egoToken } = context;
return resolvePrivateProgramList(egoToken);
},

programsByDataCenter: async (obj, args, context) => {
const { egoToken } = context;
const { shortName } = args;
const { dataCenter } = args;

const programs = await resolvePrivateProgramList(egoToken);

const filteredPrograms = programs.filter(
(program) => program.dataCenter?.shortName === shortName,
(program) => !dataCenter || program.dataCenter?.shortName === dataCenter,

This comment has been minimized.

Copy link
@ciaranschutte

ciaranschutte Nov 20, 2023

Contributor

I think you can avoid the filter iterations completely if there's no dataCenter arg?

);

return filteredPrograms;
Expand Down

0 comments on commit 821fde1

Please sign in to comment.