Skip to content

Commit

Permalink
chore: updated try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
gurusainath committed Jun 18, 2024
1 parent 8cbad90 commit 5ab1872
Showing 1 changed file with 79 additions and 63 deletions.
142 changes: 79 additions & 63 deletions web/core/store/estimates/estimate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,24 @@ export class Estimate implements IEstimate {
projectId: string,
payload: TEstimatePointsObject[]
): Promise<IEstimateType | undefined> => {
if (!this.id || !payload) return;
try {
if (!this.id || !payload) return;

const estimate = await estimateService.updateEstimate(workspaceSlug, projectId, this.id, {
estimate_points: payload,
});
runInAction(() => {
estimate?.points &&
estimate?.points.map((estimatePoint) => {
if (estimatePoint.id)
set(this.estimatePoints, [estimatePoint.id], new EstimatePoint(this.store, this.data, estimatePoint));
});
});
const estimate = await estimateService.updateEstimate(workspaceSlug, projectId, this.id, {
estimate_points: payload,
});
runInAction(() => {
estimate?.points &&
estimate?.points.map((estimatePoint) => {
if (estimatePoint.id)
set(this.estimatePoints, [estimatePoint.id], new EstimatePoint(this.store, this.data, estimatePoint));
});
});

return estimate;
return estimate;
} catch (error) {
throw error;
}
};

/**
Expand All @@ -191,25 +195,29 @@ export class Estimate implements IEstimate {
projectId: string,
payload: IEstimateFormData
): Promise<IEstimateType | undefined> => {
if (!this.id || !payload) return;
try {
if (!this.id || !payload) return;

const estimate = await estimateService.updateEstimate(workspaceSlug, projectId, this.id, payload);
if (estimate) {
runInAction(() => {
this.name = estimate?.name;
this.type = estimate?.type;
estimate?.points &&
estimate?.points.map((estimatePoint) => {
if (estimatePoint.id)
this.estimatePoints?.[estimatePoint.id]?.updateEstimatePointObject({
key: estimatePoint.key,
value: estimatePoint.value,
});
});
});
}
const estimate = await estimateService.updateEstimate(workspaceSlug, projectId, this.id, payload);
if (estimate) {
runInAction(() => {
this.name = estimate?.name;
this.type = estimate?.type;
estimate?.points &&
estimate?.points.map((estimatePoint) => {
if (estimatePoint.id)
this.estimatePoints?.[estimatePoint.id]?.updateEstimatePointObject({
key: estimatePoint.key,
value: estimatePoint.value,
});
});
});
}

return estimate;
return estimate;
} catch (error) {
throw error;
}
};

/**
Expand All @@ -224,15 +232,19 @@ export class Estimate implements IEstimate {
projectId: string,
payload: Partial<IEstimatePointType>
): Promise<IEstimatePointType | undefined> => {
if (!this.id || !payload) return;
try {
if (!this.id || !payload) return;

const estimatePoint = await estimateService.createEstimatePoint(workspaceSlug, projectId, this.id, payload);
if (estimatePoint) {
runInAction(() => {
if (estimatePoint.id) {
set(this.estimatePoints, [estimatePoint.id], new EstimatePoint(this.store, this.data, estimatePoint));
}
});
const estimatePoint = await estimateService.createEstimatePoint(workspaceSlug, projectId, this.id, payload);
if (estimatePoint) {
runInAction(() => {
if (estimatePoint.id) {
set(this.estimatePoints, [estimatePoint.id], new EstimatePoint(this.store, this.data, estimatePoint));
}
});
}
} catch (error) {
throw error;
}
};

Expand All @@ -250,37 +262,41 @@ export class Estimate implements IEstimate {
estimatePointId: string,
newEstimatePointId: string | undefined
): Promise<IEstimatePointType[] | undefined> => {
if (!this.id) return;
try {
if (!this.id) return;

const deleteEstimatePoint = await estimateService.removeEstimatePoint(
workspaceSlug,
projectId,
this.id,
estimatePointId,
newEstimatePointId ? { new_estimate_id: newEstimatePointId } : undefined
);
const deleteEstimatePoint = await estimateService.removeEstimatePoint(
workspaceSlug,
projectId,
this.id,
estimatePointId,
newEstimatePointId ? { new_estimate_id: newEstimatePointId } : undefined
);

const currentIssues = Object.values(this.store.issue.issues.issuesMap || {});
if (currentIssues && currentIssues.length > 0) {
currentIssues.map((issue) => {
if (issue.estimate_point === estimatePointId) {
this.store.issue.issues.updateIssue(issue.id, { estimate_point: newEstimatePointId });
}
});
}
const currentIssues = Object.values(this.store.issue.issues.issuesMap || {});
if (currentIssues && currentIssues.length > 0) {
currentIssues.map((issue) => {
if (issue.estimate_point === estimatePointId) {
this.store.issue.issues.updateIssue(issue.id, { estimate_point: newEstimatePointId });
}
});
}

runInAction(() => {
unset(this.estimatePoints, [estimatePointId]);
});
if (deleteEstimatePoint && deleteEstimatePoint.length > 0) {
runInAction(() => {
deleteEstimatePoint.map((estimatePoint) => {
if (estimatePoint.id)
set(this.estimatePoints, [estimatePoint.id], new EstimatePoint(this.store, this.data, estimatePoint));
});
unset(this.estimatePoints, [estimatePointId]);
});
}
if (deleteEstimatePoint) {
runInAction(() => {
deleteEstimatePoint.map((estimatePoint) => {
if (estimatePoint.id)
set(this.estimatePoints, [estimatePoint.id], new EstimatePoint(this.store, this.data, estimatePoint));
});
});
}

return deleteEstimatePoint;
return deleteEstimatePoint;
} catch (error) {
throw error;
}
};
}

0 comments on commit 5ab1872

Please sign in to comment.