plane/web/helpers/estimates.ts

34 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-05-29 09:36:39 +00:00
import { EEstimateSystem } from "@/constants/estimates";
2024-05-29 09:06:04 +00:00
export const isEstimatePointValuesRepeated = (
estimatePoints: string[],
estimateType: EEstimateSystem,
newEstimatePoint?: string | undefined
) => {
const currentEstimatePoints = estimatePoints.map((estimatePoint) => estimatePoint.trim());
let isRepeated = false;
2024-05-29 09:06:04 +00:00
if (newEstimatePoint === undefined) {
if (estimateType === EEstimateSystem.CATEGORIES) {
const points = new Set(currentEstimatePoints);
if (points.size != currentEstimatePoints.length) isRepeated = true;
2024-05-29 09:06:04 +00:00
} else if ([EEstimateSystem.POINTS, EEstimateSystem.TIME].includes(estimateType)) {
currentEstimatePoints.map((point) => {
if (Number(point) === Number(newEstimatePoint)) isRepeated = true;
2024-05-29 09:06:04 +00:00
});
}
} else {
if (estimateType === EEstimateSystem.CATEGORIES) {
currentEstimatePoints.map((point) => {
if (point === newEstimatePoint.trim()) isRepeated = true;
2024-05-29 09:06:04 +00:00
});
} else if ([EEstimateSystem.POINTS, EEstimateSystem.TIME].includes(estimateType)) {
currentEstimatePoints.map((point) => {
if (Number(point) === Number(newEstimatePoint.trim())) isRepeated = true;
2024-05-29 09:06:04 +00:00
});
}
}
return isRepeated;
2024-05-29 09:06:04 +00:00
};