Skip to content

Commit

Permalink
Remove throws to avoid breaking the process
Browse files Browse the repository at this point in the history
Remove unneeded variables from 'searchFlowsBatches'
  • Loading branch information
manelcecs committed Dec 4, 2023
1 parent 0d3b751 commit d2600f5
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 87 deletions.
9 changes: 4 additions & 5 deletions src/domain-services/categories/category-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ export class CategoryService {

const category = categories.find((cat) => cat.id === catRef.categoryID);

if (!category) {
throw new Error(`Category with ID ${catRef.categoryID} does not exist`);
}

if (!categoriesPerFlow.some((cat) => cat.id === category.id.valueOf())) {
if (
category &&
!categoriesPerFlow.some((cat) => cat.id === category.id.valueOf())
) {
const mappedCategory = this.mapCategoryToFlowCategory(category, catRef);
categoriesPerFlow.push(mappedCategory);
}
Expand Down
10 changes: 2 additions & 8 deletions src/domain-services/flows/flow-search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,28 +540,22 @@ export class FlowSearchService {
): Promise<FlowSearchResultNonPaginated> {
const flowSearchResponse = await this.search(models, args);

const batchesMissing =
Math.round(flowSearchResponse.total / args.limit) - 1;
const flows: FlowPaged[] = flowSearchResponse.flows;

let hasNextPage = flowSearchResponse.hasNextPage;
let batchCount = 1;

let cursor = flowSearchResponse.endCursor;
let nextArgs: SearchFlowsArgs = { ...args, afterCursor: cursor };

let nextFlowSearchResponse: FlowSearchResult;
while (hasNextPage) {
batchCount++;

nextFlowSearchResponse = await this.search(models, nextArgs);

flows.push(...nextFlowSearchResponse.flows);

hasNextPage =
nextFlowSearchResponse.hasNextPage && batchCount <= batchesMissing;

hasNextPage = nextFlowSearchResponse.hasNextPage;
cursor = nextFlowSearchResponse.endCursor;

// Update the cursor for the next iteration
nextArgs = { ...args, afterCursor: cursor };
}
Expand Down
1 change: 0 additions & 1 deletion src/domain-services/flows/graphql/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default class FlowResolver {
): Promise<FlowSearchResultNonPaginated> {
// Set default batch size to 1000
args.limit = args.limit > 0 ? args.limit : 1000;

return await this.flowSearchService.searchBatches(context.models, args);
}
}
19 changes: 9 additions & 10 deletions src/domain-services/location/location-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,15 @@ export class LocationService {
}
const location = locations.find((loc) => loc.id === locFO.objectID);

if (!location) {
throw new Error(`Location with ID ${locFO.objectID} does not exist`);
}
const locationsPerFlow = locationsMap.get(flowId)!;
if (!locationsPerFlow.some((loc) => loc.id === location.id)) {
const locationMapped = this.mapLocationsToFlowLocations(
location,
locFO
);
locationsPerFlow.push(locationMapped);
if (location) {
const locationsPerFlow = locationsMap.get(flowId)!;
if (!locationsPerFlow.some((loc) => loc.id === location.id)) {
const locationMapped = this.mapLocationsToFlowLocations(
location,
locFO
);
locationsPerFlow.push(locationMapped);
}
}
}
return locationsMap;
Expand Down
30 changes: 14 additions & 16 deletions src/domain-services/organizations/organization-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ export class OrganizationService {
(org) => org.id === orgFO.objectID
);

if (!organization) {
throw new Error(
`Organization with ID ${orgFO.objectID} does not exist`
);
}

const organizationPerFlow = organizationsMap.get(flowId)!;
if (
!organizationPerFlow.some((org) => org.id === organization.id.valueOf())
) {
const organizationMapped: Organization =
this.mapOrganizationsToOrganizationFlows(
organization,
orgFO.refDirection
);
organizationsMap.get(flowId)!.push(organizationMapped);
if (organization) {
const organizationPerFlow = organizationsMap.get(flowId)!;
if (
!organizationPerFlow.some(
(org) => org.id === organization.id.valueOf()
)
) {
const organizationMapped: Organization =
this.mapOrganizationsToOrganizationFlows(
organization,
orgFO.refDirection
);
organizationsMap.get(flowId)!.push(organizationMapped);
}
}
}

Expand Down
40 changes: 17 additions & 23 deletions src/domain-services/plans/plan-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,23 @@ export class PlanService {
(planFO) => planFO.objectID === plan.id
);

if (!planVersion.length) {
throw new Error(`Plan with ID ${plan.id} does not have a version`);
}

if (!planFlowObject) {
throw new Error(`Plan with ID ${plan.id} does not have a flow object`);
}

const flowId = planFlowObject && planFlowObject.flowID;

if (!plansMap.has(flowId)) {
plansMap.set(flowId, []);
}

const plansPerFlow = plansMap.get(flowId)!;

if (!plansPerFlow.some((plan) => plan.id === plan.id)) {
const planMapped = this.mapPlansToFlowPlans(
plan,
planVersion[0],
planFlowObject?.refDirection ?? null
);
plansPerFlow.push(planMapped);
if (planVersion.length && planFlowObject) {
const flowId = planFlowObject && planFlowObject.flowID;

if (!plansMap.has(flowId)) {
plansMap.set(flowId, []);
}

const plansPerFlow = plansMap.get(flowId)!;

if (!plansPerFlow.some((plan) => plan.id === plan.id)) {
const planMapped = this.mapPlansToFlowPlans(
plan,
planVersion[0],
planFlowObject?.refDirection ?? null
);
plansPerFlow.push(planMapped);
}
}
}

Expand Down
23 changes: 11 additions & 12 deletions src/domain-services/report-details/report-detail-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,18 @@ export class ReportDetailService {
(report) => report && flowId === report?.flowID
);

if (!reportDetail) {
throw new Error(`Report detail with flow ID ${flowId} does not exist`);
}
if (reportDetail) {
const reportDetailsPerFlow = reportDetailsMap.get(flowId)!;

const reportDetailsPerFlow = reportDetailsMap.get(flowId)!;
if (
!reportDetailsPerFlow.some(
(report) => report.id === reportDetail.id.valueOf()
)
) {
const reportDetailMapped =
this.mapReportDetailsToFlowReportDetail(reportDetail);
reportDetailsPerFlow.push(reportDetailMapped);
if (
!reportDetailsPerFlow.some(
(report) => report.id === reportDetail.id.valueOf()
)
) {
const reportDetailMapped =
this.mapReportDetailsToFlowReportDetail(reportDetail);
reportDetailsPerFlow.push(reportDetailMapped);
}
}
}

Expand Down
21 changes: 9 additions & 12 deletions src/domain-services/usage-years/usage-year-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,15 @@ export class UsageYearService {
(uYear) => uYear.id === usageYearFO.objectID
);

if (!usageYear) {
throw new Error(
`Usage year with ID ${usageYearFO.objectID} does not exist`
);
}
const usageYearsPerFlow = usageYearsMap.get(flowId)!;
if (!usageYearsPerFlow.some((uYear) => uYear.year === usageYear.year)) {
const usageYearMapped = this.mapUsageYearsToFlowUsageYears(
usageYear,
usageYearFO.refDirection
);
usageYearsPerFlow.push(usageYearMapped);
if (usageYear) {
const usageYearsPerFlow = usageYearsMap.get(flowId)!;
if (!usageYearsPerFlow.some((uYear) => uYear.year === usageYear.year)) {
const usageYearMapped = this.mapUsageYearsToFlowUsageYears(
usageYear,
usageYearFO.refDirection
);
usageYearsPerFlow.push(usageYearMapped);
}
}
}

Expand Down

0 comments on commit d2600f5

Please sign in to comment.