add problems to step records
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { ISODate } from '@/shared/types/date'
|
||||
|
||||
export interface StepRecordable {
|
||||
problems: string[]
|
||||
start: ISODate
|
||||
end?: ISODate
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { toISODate, type ISODate } from '@/shared/types/date'
|
||||
import type { Recordable } from '../interfaces/recordable'
|
||||
import type { StepRecordable } from '../interfaces/step-recordable'
|
||||
|
||||
export class TaskRecord implements Recordable {
|
||||
public start: ISODate = toISODate(new Date())
|
||||
public end: ISODate | undefined = undefined
|
||||
public stepRecords: Record<string, { start: ISODate; end?: ISODate }> = {}
|
||||
public stepRecords: Record<string, StepRecordable> = {}
|
||||
|
||||
public constructor(
|
||||
public readonly id: string,
|
||||
@@ -21,4 +22,14 @@ export class TaskRecord implements Recordable {
|
||||
|
||||
return Math.round(durationMilliseconds / (1000 * 60))
|
||||
}
|
||||
|
||||
public static fromRecordable(recordable: Recordable) {
|
||||
const taskRecord = new TaskRecord(recordable.id, recordable.taskId)
|
||||
|
||||
taskRecord.stepRecords = recordable.stepRecords
|
||||
taskRecord.start = recordable.start
|
||||
taskRecord.end = recordable.end
|
||||
|
||||
return taskRecord
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { ISODate } from '@/shared/types/date'
|
||||
import { defineStore } from 'pinia'
|
||||
import type { Recordable } from '../interfaces/recordable'
|
||||
import type { StepRecordable } from '../interfaces/step-recordable'
|
||||
import type { TaskRecord } from '../models/task-record'
|
||||
import { TaskRecord } from '../models/task-record'
|
||||
|
||||
type RecordId = string
|
||||
|
||||
@@ -42,6 +42,7 @@ export const useTaskRecordStore = defineStore('task-record-store', {
|
||||
start: ISODate
|
||||
}) {
|
||||
this.records[params.recordId].stepRecords[params.stepId] = {
|
||||
problems: [],
|
||||
start: params.start
|
||||
}
|
||||
},
|
||||
@@ -54,13 +55,22 @@ export const useTaskRecordStore = defineStore('task-record-store', {
|
||||
}
|
||||
|
||||
stepRecord.end = params.end
|
||||
},
|
||||
addProblemToStepRecord(recordId: string, stepId: string, problem: string) {
|
||||
const stepRecord = this.getStepRecord(recordId, stepId)
|
||||
|
||||
if (!stepRecord) {
|
||||
return
|
||||
}
|
||||
|
||||
stepRecord.problems.push(problem)
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
getTaskRecords() {
|
||||
return (taskId: string): Recordable[] =>
|
||||
this.taskRecordMaps?.[taskId]?.map(
|
||||
(recordId) => this.records[recordId]
|
||||
return (taskId: string): TaskRecord[] =>
|
||||
this.taskRecordMaps?.[taskId]?.map((recordId) =>
|
||||
TaskRecord.fromRecordable(this.records[recordId])
|
||||
) ?? []
|
||||
},
|
||||
getStepRecord() {
|
||||
|
||||
Reference in New Issue
Block a user