Skip to content

Commit

Permalink
fix(cards): subscription data fetching with errors in cards (#3973)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mambatukaa committed Jan 4, 2023
1 parent 05540b4 commit 5bd9832
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 72 deletions.
Expand Up @@ -91,10 +91,9 @@ export default {
async companies(
deal: IDealDocument,
_args,
{ subdomain, serverTiming }: IContext
{ subdomain }: IContext,
{ isSubscription }
) {
serverTiming.startTime('companiesResolver:savedConformity');

const companyIds = await sendCoreMessage({
subdomain,
action: 'conformities.savedConformity',
Expand All @@ -107,10 +106,6 @@ export default {
defaultValue: []
});

serverTiming.endTime('companiesResolver:savedConformity');

serverTiming.startTime('companiesResolver:findActiveCompanies');

const activeCompanies = await sendContactsMessage({
subdomain,
action: 'companies.findActiveCompanies',
Expand All @@ -119,23 +114,22 @@ export default {
defaultValue: []
});

const response = (activeCompanies || []).map(c => ({
if (isSubscription) {
return activeCompanies;
}

return (activeCompanies || []).map(c => ({
__typename: 'Company',
_id: c._id
}));

serverTiming.endTime('companiesResolver:findActiveCompanies');

return response;
},

async customers(
deal: IDealDocument,
_args,
{ subdomain, serverTiming }: IContext
{ subdomain }: IContext,
{ isSubscription }
) {
serverTiming.startTime('customersResolver:savedConformity');

const customerIds = await sendCoreMessage({
subdomain,
action: 'conformities.savedConformity',
Expand All @@ -148,10 +142,6 @@ export default {
defaultValue: []
});

serverTiming.endTime('customersResolver:savedConformity');

serverTiming.startTime('customersResolver:findActiveCustomers');

const activeCustomers = await sendContactsMessage({
subdomain,
action: 'customers.findActiveCustomers',
Expand All @@ -160,35 +150,45 @@ export default {
defaultValue: []
});

const response = (activeCustomers || []).map(c => ({
if (isSubscription) {
return activeCustomers;
}

return (activeCustomers || []).map(c => ({
__typename: 'Customer',
_id: c._id
}));

serverTiming.endTime('customersResolver:findActiveCustomers');

return response;
},

async products(
deal: IDealDocument,
_args,
{ subdomain, serverTiming }: IContext
) {
serverTiming.startTime('customersResolver:products');

async products(deal: IDealDocument, _args, { subdomain }: IContext) {
const response = await generateProducts(subdomain, deal.productsData);

serverTiming.endTime('customersResolver:products');

return response;
},

amount(deal: IDealDocument) {
return generateAmounts(deal.productsData || []);
},

assignedUsers(deal: IDealDocument) {
assignedUsers(
deal: IDealDocument,
_args,
{ subdomain }: IContext,
{ isSubscription }
) {
if (isSubscription && deal.assignedUserIds?.length) {
return sendCoreMessage({
subdomain,
action: 'users.find',
data: {
query: {
_id: { $in: deal.assignedUserIds }
}
},
isRPC: true
});
}

return (deal.assignedUserIds || [])
.filter(e => e)
.map(_id => ({
Expand Down Expand Up @@ -221,13 +221,7 @@ export default {
return false;
},

async hasNotified(
deal: IDealDocument,
_args,
{ user, subdomain, serverTiming }: IContext
) {
serverTiming.startTime('hasNotifified');

async hasNotified(deal: IDealDocument, _args, { user, subdomain }: IContext) {
const response = await sendNotificationsMessage({
subdomain,
action: 'checkIfRead',
Expand All @@ -237,8 +231,6 @@ export default {
}
});

serverTiming.endTime('hasNotifified');

return response;
},

Expand Down
@@ -1,7 +1,7 @@
import { IGrowthHackDocument } from '../../../models/definitions/growthHacks';
import { boardId } from '../../utils';
import { IContext } from '../../../connectionResolver';
import { sendFormsMessage } from '../../../messageBroker';
import { sendCoreMessage, sendFormsMessage } from '../../../messageBroker';

export default {
__resolveReference({ _id }, { models }: IContext) {
Expand Down Expand Up @@ -62,7 +62,25 @@ export default {
});
},

assignedUsers(growthHack: IGrowthHackDocument) {
assignedUsers(
growthHack: IGrowthHackDocument,
_args,
{ subdomain }: IContext,
{ isSubscription }
) {
if (isSubscription && growthHack.assignedUserIds?.length) {
return sendCoreMessage({
subdomain,
action: 'users.find',
data: {
query: {
_id: { $in: growthHack.assignedUserIds }
}
},
isRPC: true
});
}

return (growthHack.assignedUserIds || [])
.filter(e => e)
.map(_id => ({
Expand Down
Expand Up @@ -12,7 +12,12 @@ export default {
return models.Tasks.findOne({ _id });
},

async companies(task: ITaskDocument, _args, { subdomain }: IContext) {
async companies(
task: ITaskDocument,
_args,
{ subdomain }: IContext,
{ isSubscription }
) {
const companyIds = await sendCoreMessage({
subdomain,
action: 'conformities.savedConformity',
Expand All @@ -33,6 +38,10 @@ export default {
defaultValue: []
});

if (isSubscription) {
return activeCompanies;
}

return (activeCompanies || []).map(({ _id }) => ({
__typename: 'Company',
_id
Expand All @@ -47,7 +56,12 @@ export default {
return { __typename: 'User', _id: task.userId };
},

async customers(task: ITaskDocument, _args, { subdomain }: IContext) {
async customers(
task: ITaskDocument,
_args,
{ subdomain }: IContext,
{ isSubscription }
) {
const customerIds = await sendCoreMessage({
subdomain,
action: 'conformities.savedConformity',
Expand All @@ -72,13 +86,35 @@ export default {
defaultValue: []
});

if (isSubscription) {
return customers;
}

return (customers || []).map(({ _id }) => ({
__typename: 'Customer',
_id
}));
},

assignedUsers(task: ITaskDocument) {
assignedUsers(
task: ITaskDocument,
_args,
{ subdomain }: IContext,
{ isSubscription }
) {
if (isSubscription && task.assignedUserIds?.length) {
return sendCoreMessage({
subdomain,
action: 'users.find',
data: {
query: {
_id: { $in: task.assignedUserIds }
}
},
isRPC: true
});
}

return (task.assignedUserIds || [])
.filter(e => e)
.map(_id => ({
Expand Down
Expand Up @@ -12,7 +12,12 @@ export default {
return models.Tickets.findOne({ _id });
},

async companies(ticket: ITicketDocument, _args, { subdomain }: IContext) {
async companies(
ticket: ITicketDocument,
_args,
{ subdomain }: IContext,
{ isSubscription }
) {
const companyIds = await sendCoreMessage({
subdomain,
action: 'conformities.savedConformity',
Expand All @@ -33,10 +38,19 @@ export default {
defaultValue: []
});

if (isSubscription) {
return companies;
}

return (companies || []).map(({ _id }) => ({ __typename: 'Company', _id }));
},

async customers(ticket: ITicketDocument, _args, { subdomain }: IContext) {
async customers(
ticket: ITicketDocument,
_args,
{ subdomain }: IContext,
{ isSubscription }
) {
const customerIds = await sendCoreMessage({
subdomain,
action: 'conformities.savedConformity',
Expand All @@ -61,13 +75,35 @@ export default {
defaultValue: []
});

if (isSubscription) {
return customers;
}

return (customers || []).map(({ _id }) => ({
__typename: 'Customer',
_id
}));
},

assignedUsers(ticket: ITicketDocument) {
assignedUsers(
ticket: ITicketDocument,
_args,
{ subdomain }: IContext,
{ isSubscription }
) {
if (isSubscription && ticket.assignedUserIds?.length) {
return sendCoreMessage({
subdomain,
action: 'users.find',
data: {
query: {
_id: { $in: ticket.assignedUserIds }
}
},
isRPC: true
});
}

return (ticket.assignedUserIds || [])
.filter(e => e)
.map(_id => ({
Expand Down

0 comments on commit 5bd9832

Please sign in to comment.