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, adaptStepsToTextarea,
adaptTextareaToSteps adaptTextareaToSteps
} from '../infra/adaptStepsToTextarea' } from '../infra/adaptStepsToTextarea'
import type { Step } from '../models/step' import type { Stepable } from '../interfaces/stepable'
const props = defineProps<{ const props = defineProps<{
modelValue: Step[] modelValue: Stepable[]
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
(event: 'update:modelValue', payload: Step[]): void (event: 'update:modelValue', payload: Stepable[]): void
}>() }>()
const rawSteps = ref(adaptStepsToTextarea(props.modelValue)) const rawSteps = ref(adaptStepsToTextarea(props.modelValue))

View File

@@ -1,7 +1,7 @@
import { createUuid } from '@/shared/create-uuid' 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') steps.map((step) => `- ${step.title} | ${step.estimation}`).join('\n')
const extractTitleAndEstimationFromStep = ( const extractTitleAndEstimationFromStep = (
@@ -23,7 +23,7 @@ const extractTitleAndEstimationFromStep = (
return [title, estimation] return [title, estimation]
} }
export const adaptTextareaToSteps = (textareaValue: string): Step[] => export const adaptTextareaToSteps = (textareaValue: string): Stepable[] =>
textareaValue textareaValue
.split('\n') .split('\n')
.map((rawStep) => { .map((rawStep) => {
@@ -33,6 +33,6 @@ export const adaptTextareaToSteps = (textareaValue: string): Step[] =>
return null 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 type { Stepable } from '@/modules/task/interfaces/stepable'
import { Step } from '@/modules/task/models/step'
import { faker } from '@faker-js/faker' import { faker } from '@faker-js/faker'
export const createStepFixture = (partialStep?: Partial<Stepable>) => export const createStepFixture = (partialStep?: Partial<Stepable>) => ({
new Step( id: partialStep?.id ?? faker.datatype.uuid(),
partialStep?.id ?? faker.datatype.uuid(), title: partialStep?.title ?? faker.animal.bird(),
partialStep?.title ?? faker.animal.bird(), estimation:
partialStep?.estimation ?? partialStep?.estimation ??
faker.datatype.number({ faker.datatype.number({
min: 0, min: 0,
max: 40 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 { Stepable } from '@/modules/task/interfaces/stepable'
import type { Taskable } from '@/modules/task/interfaces/taskable' import type { Taskable } from '@/modules/task/interfaces/taskable'
import { Step } from '@/modules/task/models/step'
import { toISODate } from '@/shared/types/date' import { toISODate } from '@/shared/types/date'
export class Task implements Taskable { export class Task implements Taskable {
public date = toISODate(new Date()) public date = toISODate(new Date())
public steps: Step[] = [] public steps: Stepable[] = []
public link: string | null = null public link: string | null = null
constructor(public readonly id: string, public readonly title: string) {} constructor(public readonly id: string, public readonly title: string) {}
public addSteps(...steps: Stepable[]) { public addSteps(...steps: Stepable[]) {
this.steps.push(...Step.fromStepable(...steps)) this.steps.push(...steps)
return this return this
} }

View File

@@ -1,6 +1,6 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import type { Stepable } from '../interfaces/stepable'
import type { Taskable } from '../interfaces/taskable' import type { Taskable } from '../interfaces/taskable'
import type { Step } from '../models/step'
import { Task } from '../models/task' import { Task } from '../models/task'
export interface TaskStoreState { export interface TaskStoreState {
@@ -31,7 +31,7 @@ export const useTaskStore = defineStore('task-store', {
this.recentTasks.find((task) => task.id === taskId) ?? null this.recentTasks.find((task) => task.id === taskId) ?? null
}, },
getStep() { 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 this.getTask(taskId)?.steps.find((step) => step.id === stepId) ?? null
} }
} }