feat: Add delay until action for delay app

This commit is contained in:
Faruk AYDIN
2022-12-16 03:15:30 +03:00
committed by Ali BARIN
parent 5d9ed13003
commit cb58ab5fb7
6 changed files with 81 additions and 26 deletions

View File

@@ -1,21 +1,25 @@
export type TDelayForUnit = 'minutes' | 'hours' | 'days' | 'weeks';
import Step from '../models/step';
import delayForAsMilliseconds, {
TDelayForUnit,
} from './delay-for-as-milliseconds';
import delayUntilAsMilliseconds from './delay-until-as-milliseconds';
const delayAsMilliseconds = (
delayForUnit: TDelayForUnit,
delayForValue: number
) => {
switch (delayForUnit) {
case 'minutes':
return delayForValue * 60 * 1000;
case 'hours':
return delayForValue * 60 * 60 * 1000;
case 'days':
return delayForValue * 24 * 60 * 60 * 1000;
case 'weeks':
return delayForValue * 7 * 24 * 60 * 60 * 1000;
default:
return 0;
const delayAsMilliseconds = (step: Step) => {
let delayDuration = 0;
if (step.key === 'delayFor') {
const { delayForUnit, delayForValue } = step.parameters;
delayDuration = delayForAsMilliseconds(
delayForUnit as TDelayForUnit,
Number(delayForValue)
);
} else if (step.key === 'delayUntil') {
const { delayUntil } = step.parameters;
delayDuration = delayUntilAsMilliseconds(delayUntil as string);
}
return delayDuration;
};
export default delayAsMilliseconds;