init
This commit is contained in:
51
src/use-cases/task/models/step.ts
Normal file
51
src/use-cases/task/models/step.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import type { Stepable } from '@/use-cases/task/interfaces/stepable'
|
||||
|
||||
export class Step implements Stepable {
|
||||
private _steps: Step[] = []
|
||||
|
||||
constructor(
|
||||
readonly id: string,
|
||||
readonly title: string,
|
||||
readonly estimation?: number
|
||||
) {
|
||||
return this
|
||||
}
|
||||
|
||||
public get steps() {
|
||||
return this._steps
|
||||
}
|
||||
|
||||
public addSteps(...steps: Stepable[]) {
|
||||
this._steps.push(...Step.fromStepable(...steps))
|
||||
return this
|
||||
}
|
||||
|
||||
public removeStep(index: number) {
|
||||
if (index < 0 || index >= this._steps.length) {
|
||||
return
|
||||
}
|
||||
|
||||
this._steps.splice(index)
|
||||
}
|
||||
|
||||
public get totalEstimation(): number {
|
||||
return (
|
||||
this.estimation ??
|
||||
this._steps.reduce((acc, step) => acc + step.totalEstimation, 0)
|
||||
)
|
||||
}
|
||||
|
||||
public static fromStepable(...stepables: Stepable[]): Step[] {
|
||||
return stepables.map((stepable) =>
|
||||
new Step(stepable.id, stepable.title, stepable.estimation).addSteps(
|
||||
...Step.fromStepable(...stepable.steps)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
public static getStepLeafs(steps: Stepable[]): Stepable[] {
|
||||
return steps.flatMap((step) =>
|
||||
step.steps.length > 0 ? Step.getStepLeafs(step.steps) : [step]
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user