rename use-case to modules

This commit is contained in:
Julien Calixte
2023-04-09 12:34:43 +02:00
parent 5719fabac1
commit cd49c4cf0a
20 changed files with 17 additions and 17 deletions

View File

@@ -0,0 +1,38 @@
import { createUuid } from '@/shared/create-uuid'
import { Step } from '../models/step'
export const adaptStepsToTextarea = (steps: Step[]) =>
steps.map((step) => `- ${step.title} | ${step.estimation}`).join('\n')
const extractTitleAndEstimationFromStep = (
rawStep: string
): [string, number] => {
const [rawTitle, rawEstimation] = rawStep
.trim()
.replace(/^-\s*/, '')
.split('|')
const title = rawTitle.trim()
const estimationString = (rawEstimation || '').trim()
const estimation = Number(estimationString)
if (isNaN(estimation)) {
return [title, 0]
}
return [title, estimation]
}
export const adaptTextareaToSteps = (textareaValue: string): Step[] =>
textareaValue
.split('\n')
.map((rawStep) => {
const [title, estimation] = extractTitleAndEstimationFromStep(rawStep)
if (!title) {
return null
}
return new Step(createUuid(), title, estimation)
})
.filter((step) => step !== null) as Step[]