diff --git a/src/modules/task/components/StepInput.vue b/src/modules/task/components/StepInput.vue index f5d0a50..66d1088 100644 --- a/src/modules/task/components/StepInput.vue +++ b/src/modules/task/components/StepInput.vue @@ -4,14 +4,14 @@ import { adaptStepsToTextarea, adaptTextareaToSteps } from '../infra/adaptStepsToTextarea' -import type { Step } from '../models/step' +import type { Stepable } from '../interfaces/stepable' const props = defineProps<{ - modelValue: Step[] + modelValue: Stepable[] }>() const emit = defineEmits<{ - (event: 'update:modelValue', payload: Step[]): void + (event: 'update:modelValue', payload: Stepable[]): void }>() const rawSteps = ref(adaptStepsToTextarea(props.modelValue)) diff --git a/src/modules/task/infra/adaptStepsToTextarea.ts b/src/modules/task/infra/adaptStepsToTextarea.ts index 1ffba3c..e841d00 100644 --- a/src/modules/task/infra/adaptStepsToTextarea.ts +++ b/src/modules/task/infra/adaptStepsToTextarea.ts @@ -1,7 +1,7 @@ import { createUuid } from '@/shared/create-uuid' -import { Step } from '../models/step' +import type { Stepable } from '../interfaces/stepable' -export const adaptStepsToTextarea = (steps: Step[]) => +export const adaptStepsToTextarea = (steps: Stepable[]) => steps.map((step) => `- ${step.title} | ${step.estimation}`).join('\n') const extractTitleAndEstimationFromStep = ( @@ -23,7 +23,7 @@ const extractTitleAndEstimationFromStep = ( return [title, estimation] } -export const adaptTextareaToSteps = (textareaValue: string): Step[] => +export const adaptTextareaToSteps = (textareaValue: string): Stepable[] => textareaValue .split('\n') .map((rawStep) => { @@ -33,6 +33,6 @@ export const adaptTextareaToSteps = (textareaValue: string): Step[] => return null } - return new Step(createUuid(), title, estimation) + return { id: createUuid(), title, estimation } }) - .filter((step) => step !== null) as Step[] + .filter((step) => step !== null) as Stepable[] diff --git a/src/modules/task/models/step.fixture.ts b/src/modules/task/models/step.fixture.ts index 211b4e2..87620a1 100644 --- a/src/modules/task/models/step.fixture.ts +++ b/src/modules/task/models/step.fixture.ts @@ -1,14 +1,13 @@ import type { Stepable } from '@/modules/task/interfaces/stepable' -import { Step } from '@/modules/task/models/step' import { faker } from '@faker-js/faker' -export const createStepFixture = (partialStep?: Partial) => - new Step( - partialStep?.id ?? faker.datatype.uuid(), - partialStep?.title ?? faker.animal.bird(), +export const createStepFixture = (partialStep?: Partial) => ({ + id: partialStep?.id ?? faker.datatype.uuid(), + title: partialStep?.title ?? faker.animal.bird(), + estimation: partialStep?.estimation ?? - faker.datatype.number({ - min: 0, - max: 40 - }) - ) + faker.datatype.number({ + min: 0, + max: 40 + }) +}) diff --git a/src/modules/task/models/step.ts b/src/modules/task/models/step.ts deleted file mode 100644 index 80449d1..0000000 --- a/src/modules/task/models/step.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { Stepable } from '@/modules/task/interfaces/stepable' - -export class Step implements Stepable { - constructor( - readonly id: string, - readonly title: string, - readonly estimation: number - ) { - return this - } - - public static fromStepable(...stepables: Stepable[]): Step[] { - return stepables.map( - (stepable) => new Step(stepable.id, stepable.title, stepable.estimation) - ) - } -} diff --git a/src/modules/task/models/task.ts b/src/modules/task/models/task.ts index 71168f5..0046391 100644 --- a/src/modules/task/models/task.ts +++ b/src/modules/task/models/task.ts @@ -1,17 +1,16 @@ import type { Stepable } from '@/modules/task/interfaces/stepable' import type { Taskable } from '@/modules/task/interfaces/taskable' -import { Step } from '@/modules/task/models/step' import { toISODate } from '@/shared/types/date' export class Task implements Taskable { public date = toISODate(new Date()) - public steps: Step[] = [] + public steps: Stepable[] = [] public link: string | null = null constructor(public readonly id: string, public readonly title: string) {} public addSteps(...steps: Stepable[]) { - this.steps.push(...Step.fromStepable(...steps)) + this.steps.push(...steps) return this } diff --git a/src/modules/task/stores/useTask.store.ts b/src/modules/task/stores/useTask.store.ts index f3418b2..304099a 100644 --- a/src/modules/task/stores/useTask.store.ts +++ b/src/modules/task/stores/useTask.store.ts @@ -1,6 +1,6 @@ import { defineStore } from 'pinia' +import type { Stepable } from '../interfaces/stepable' import type { Taskable } from '../interfaces/taskable' -import type { Step } from '../models/step' import { Task } from '../models/task' export interface TaskStoreState { @@ -31,7 +31,7 @@ export const useTaskStore = defineStore('task-store', { this.recentTasks.find((task) => task.id === taskId) ?? null }, getStep() { - return (taskId: string, stepId: string): Step | null => + return (taskId: string, stepId: string): Stepable | null => this.getTask(taskId)?.steps.find((step) => step.id === stepId) ?? null } }