Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Imperio authored and Felipe Imperio committed Oct 29, 2024
1 parent 123be6c commit 3fe3cce
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 115 deletions.
6 changes: 4 additions & 2 deletions src/entities/activity/model/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ function mapConditionalLogic(dto: ConditionalLogicDto | null) {
case 'NOT_INCLUDES_OPTION':
case 'EQUAL_TO_OPTION':
case 'NOT_EQUAL_TO_OPTION':
updatedCondition.payload = { optionValue: condition.payload.optionValue };
updatedCondition.payload = {
optionValue: condition.payload.optionValue,
};
break;

case 'GREATER_THAN_DATE':
Expand Down Expand Up @@ -179,7 +181,7 @@ function mapToAbTest(dto: ABTrailsItemDto): ActivityItem {
fontSizeBeginEnd: nodesSettingsDto.fontSizeBeginEnd,
},
deviceType: config.deviceType,
nodes: nodes.map<TestNode>(x => ({
nodes: nodes.map<TestNode>(x => ({
...x,
})),
tutorials: tutorials.tutorials.map<TutorialRecord>(x => ({
Expand Down
9 changes: 2 additions & 7 deletions src/entities/conditional-logic/model/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ export const isBetweenTimes = (
maxTime: { hours: number; minutes: number },
) => {
if (!input) return false;
return (
isGreaterThanTime(input, minTime) && isLessThanTime(input, maxTime)
);
return isGreaterThanTime(input, minTime) && isLessThanTime(input, maxTime);
};

export const isOutsideOfTimes = (
Expand All @@ -170,8 +168,5 @@ export const isOutsideOfTimes = (
maxTime: { hours: number; minutes: number },
) => {
if (!input) return false;
return (
isLessThanTime(input, minTime) || isGreaterThanTime(input, maxTime)
);
return isLessThanTime(input, minTime) || isGreaterThanTime(input, maxTime);
};

56 changes: 39 additions & 17 deletions src/features/pass-survey/model/AnswerValidator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { isBefore, isAfter, isEqual } from 'date-fns';
import { parseISO } from 'date-fns';

import {
doesNotIncludeValue,
includesValue,
Expand All @@ -19,10 +22,9 @@ import {
TimeRangeResponse,
} from '../lib/types/payload';

import { isBefore, isAfter, isEqual } from 'date-fns';
import { parseISO } from 'date-fns';

export function AnswerValidator(params?: AnswerValidatorArgs): IAnswerValidator {
export function AnswerValidator(
params?: AnswerValidatorArgs,
): IAnswerValidator {
const { items, answers, step = 0 } = params ?? {};
const currentPipelineItem = items?.[step];
const currentAnswer = answers?.[step];
Expand All @@ -31,9 +33,12 @@ export function AnswerValidator(params?: AnswerValidatorArgs): IAnswerValidator
const answer = currentAnswer?.answer as Maybe<string>;
return answer ?? null;
};

const getAnswerTime = (): { hours: number; minutes: number } | null => {
const answer = currentAnswer?.answer as Maybe<{ hours: number; minutes: number }>;
const answer = currentAnswer?.answer as Maybe<{
hours: number;
minutes: number;
}>;
return answer ?? null;
};

Expand Down Expand Up @@ -88,12 +93,20 @@ export function AnswerValidator(params?: AnswerValidatorArgs): IAnswerValidator
return rowValue !== null && rowValue < value;
},

isBetweenSliderRowValues(rowIndex: number, minValue: number, maxValue: number) {
isBetweenSliderRowValues(
rowIndex: number,
minValue: number,
maxValue: number,
) {
const rowValue = getSliderRowValue(rowIndex);
return rowValue !== null && rowValue >= minValue && rowValue <= maxValue;
},

isOutsideOfSliderRowValues(rowIndex: number, minValue: number, maxValue: number) {
isOutsideOfSliderRowValues(
rowIndex: number,
minValue: number,
maxValue: number,
) {
const rowValue = getSliderRowValue(rowIndex);
return rowValue !== null && (rowValue < minValue || rowValue > maxValue);
},
Expand All @@ -111,13 +124,18 @@ export function AnswerValidator(params?: AnswerValidatorArgs): IAnswerValidator

includesRowOption(rowIndex: number, optionValue: string) {
const selectedOption = getRowOptionValue(rowIndex);
return selectedOption !== null && includesValue([selectedOption], optionValue);
return (
selectedOption !== null && includesValue([selectedOption], optionValue)
);
},

notIncludesRowOption(rowIndex: number, optionValue: string) {
const selectedOption = getRowOptionValue(rowIndex);
return selectedOption !== null && doesNotIncludeValue([selectedOption], optionValue);
},
return (
selectedOption !== null &&
doesNotIncludeValue([selectedOption], optionValue)
);
},

isBetweenValues(min: number, max: number) {
const answer = currentAnswer?.answer as Maybe<number>;
Expand Down Expand Up @@ -171,7 +189,9 @@ export function AnswerValidator(params?: AnswerValidatorArgs): IAnswerValidator

isLessThanDate(date: string) {
const answerDate = getAnswerDate();
return answerDate ? isBefore(parseISO(answerDate), parseISO(date)) : false;
return answerDate
? isBefore(parseISO(answerDate), parseISO(date))
: false;
},

isEqualToDate(date: string) {
Expand All @@ -181,22 +201,24 @@ export function AnswerValidator(params?: AnswerValidatorArgs): IAnswerValidator

isNotEqualToDate(date: string) {
const answerDate = getAnswerDate();
return answerDate ? !isEqual(parseISO(answerDate), parseISO(date)) : false;
return answerDate
? !isEqual(parseISO(answerDate), parseISO(date))
: false;
},

isBetweenDates(minDate: string, maxDate: string) {
const answerDate = getAnswerDate();
return answerDate
? !isBefore(parseISO(answerDate), parseISO(minDate)) &&
!isAfter(parseISO(answerDate), parseISO(maxDate))
!isAfter(parseISO(answerDate), parseISO(maxDate))
: false;
},

isOutsideOfDates(minDate: string, maxDate: string) {
const answerDate = getAnswerDate();
return answerDate
? isBefore(parseISO(answerDate), parseISO(minDate)) ||
isAfter(parseISO(answerDate), parseISO(maxDate))
isAfter(parseISO(answerDate), parseISO(maxDate))
: false;
},

Expand Down Expand Up @@ -235,7 +257,7 @@ export function AnswerValidator(params?: AnswerValidatorArgs): IAnswerValidator
const answerTime = getAnswerTime();
return answerTime
? timeToMinutes(answerTime) >= timeToMinutes(minTime) &&
timeToMinutes(answerTime) <= timeToMinutes(maxTime)
timeToMinutes(answerTime) <= timeToMinutes(maxTime)
: false;
},

Expand All @@ -246,7 +268,7 @@ export function AnswerValidator(params?: AnswerValidatorArgs): IAnswerValidator
const answerTime = getAnswerTime();
return answerTime
? timeToMinutes(answerTime) < timeToMinutes(minTime) ||
timeToMinutes(answerTime) > timeToMinutes(maxTime)
timeToMinutes(answerTime) > timeToMinutes(maxTime)
: false;
},

Expand Down
2 changes: 1 addition & 1 deletion src/features/pass-survey/model/IAnswerValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export interface IAnswerValidator {
minValue: number,
maxValue: number,
): boolean;

isEqualToRowOption(rowIndex: number, optionValue: string): boolean;

isNotEqualToRowOption(rowIndex: number, optionValue: string): boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function PipelineVisibilityChecker(
condition.payload.minTime,
condition.payload.maxTime,
);

case 'EQUAL_TO_SLIDER_ROWS':
return answerValidator.isEqualToSliderRow(
condition.payload.rowIndex,
Expand Down
Loading

0 comments on commit 3fe3cce

Please sign in to comment.