remove unecessary Step class

This commit is contained in:
Julien Calixte
2023-04-11 23:06:44 +02:00
parent 058046ad1f
commit c8722cad06
6 changed files with 21 additions and 40 deletions

View File

@@ -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))

View File

@@ -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[]

View File

@@ -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<Stepable>) =>
new Step(
partialStep?.id ?? faker.datatype.uuid(),
partialStep?.title ?? faker.animal.bird(),
export const createStepFixture = (partialStep?: Partial<Stepable>) => ({
id: partialStep?.id ?? faker.datatype.uuid(),
title: partialStep?.title ?? faker.animal.bird(),
estimation:
partialStep?.estimation ??
faker.datatype.number({
min: 0,
max: 40
})
)
})

View File

@@ -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)
)
}
}

View File

@@ -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
}

View File

@@ -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
}
}