60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
|
|
import { Task, TaskState, StateHistoryEntry } from '@app/features/tasks/data-access/models/task.model';
|
||
|
|
|
||
|
|
export class TaskBuilder {
|
||
|
|
private task: Task = {
|
||
|
|
id: 'task-001',
|
||
|
|
title: 'Default Task',
|
||
|
|
description: 'Default description',
|
||
|
|
dueDate: '2030-01-01',
|
||
|
|
stateHistory: [{ state: 'new', date: '2026-01-01' }],
|
||
|
|
notes: [],
|
||
|
|
};
|
||
|
|
|
||
|
|
withId(id: string): this {
|
||
|
|
this.task.id = id;
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
withTitle(title: string): this {
|
||
|
|
this.task.title = title;
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
withDescription(description: string): this {
|
||
|
|
this.task.description = description;
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
withDueDate(dueDate: string): this {
|
||
|
|
this.task.dueDate = dueDate;
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
withState(state: TaskState, date?: string): this {
|
||
|
|
this.task.stateHistory = [{ state, date: date ?? '2026-01-01' }];
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
withStateHistory(stateHistory: StateHistoryEntry[]): this {
|
||
|
|
this.task.stateHistory = stateHistory;
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
withNotes(notes: string[]): this {
|
||
|
|
this.task.notes = notes;
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
build(): Task {
|
||
|
|
return { ...this.task };
|
||
|
|
}
|
||
|
|
|
||
|
|
static buildMany(count: number, customize?: (builder: TaskBuilder, index: number) => void): Task[] {
|
||
|
|
return Array.from({ length: count }, (_, i) => {
|
||
|
|
const builder = new TaskBuilder().withId(`task-${i + 1}`).withTitle(`Task ${i + 1}`);
|
||
|
|
customize?.(builder, i);
|
||
|
|
return builder.build();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|