Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
perf(integrations): add brand restriction option to integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
munkhorgil committed Jun 11, 2020
1 parent d98af15 commit ff534a0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/apolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const apolloServer = new ApolloServer({
if (USE_BRAND_RESTRICTIONS !== 'true') {
return {
brandIdSelector: {},
singleBrandIdSelector: {},
userBrandIdsSelector: {},
docModifier: doc => doc,
commonQuerySelector: {},
Expand All @@ -80,6 +81,7 @@ const apolloServer = new ApolloServer({
let commonQuerySelector = {};
let commonQuerySelectorElk;
let userBrandIdsSelector = {};
let singleBrandIdSelector = {};

if (user) {
brandIds = user.brandIds || [];
Expand All @@ -93,11 +95,13 @@ const apolloServer = new ApolloServer({
commonQuerySelector = { scopeBrandIds: { $in: scopeBrandIds } };
commonQuerySelectorElk = { terms: { scopeBrandIds } };
userBrandIdsSelector = { brandIds: { $in: scopeBrandIds } };
singleBrandIdSelector = { brandId: { $in: scopeBrandIds } };
}
}

return {
brandIdSelector,
singleBrandIdSelector,
docModifier: doc => ({ ...doc, scopeBrandIds }),
commonQuerySelector,
commonQuerySelectorElk,
Expand Down
4 changes: 3 additions & 1 deletion src/data/resolvers/queries/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ const integrationQueries = {
page: number;
perPage: number;
kind: string;

searchValue: string;
channelId: string;
brandId: string;
tag: string;
},
{ singleBrandIdSelector }: IContext,
) {
const query = await generateFilterQuery(args);
const query = { ...singleBrandIdSelector, ...(await generateFilterQuery(args)) };
const integrations = paginate(Integrations.findIntegrations(query), args);

return integrations.sort({ name: 1 });
Expand Down
1 change: 1 addition & 0 deletions src/data/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface IContext {
userBrandIdsSelector: {};
commonQuerySelector: {};
commonQuerySelectorElk: {};
singleBrandIdSelector: {};
dataSources: {
EngagesAPI: any;
IntegrationsAPI: any;
Expand Down

0 comments on commit ff534a0

Please sign in to comment.