add problems to step records

This commit is contained in:
Julien Calixte
2023-04-10 13:01:37 +02:00
parent d517853472
commit d97b297c9b
3 changed files with 27 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import type { ISODate } from '@/shared/types/date' import type { ISODate } from '@/shared/types/date'
export interface StepRecordable { export interface StepRecordable {
problems: string[]
start: ISODate start: ISODate
end?: ISODate end?: ISODate
} }

View File

@@ -1,10 +1,11 @@
import { toISODate, type ISODate } from '@/shared/types/date' import { toISODate, type ISODate } from '@/shared/types/date'
import type { Recordable } from '../interfaces/recordable' import type { Recordable } from '../interfaces/recordable'
import type { StepRecordable } from '../interfaces/step-recordable'
export class TaskRecord implements Recordable { export class TaskRecord implements Recordable {
public start: ISODate = toISODate(new Date()) public start: ISODate = toISODate(new Date())
public end: ISODate | undefined = undefined public end: ISODate | undefined = undefined
public stepRecords: Record<string, { start: ISODate; end?: ISODate }> = {} public stepRecords: Record<string, StepRecordable> = {}
public constructor( public constructor(
public readonly id: string, public readonly id: string,
@@ -21,4 +22,14 @@ export class TaskRecord implements Recordable {
return Math.round(durationMilliseconds / (1000 * 60)) 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
}
} }

View File

@@ -2,7 +2,7 @@ import type { ISODate } from '@/shared/types/date'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import type { Recordable } from '../interfaces/recordable' import type { Recordable } from '../interfaces/recordable'
import type { StepRecordable } from '../interfaces/step-recordable' import type { StepRecordable } from '../interfaces/step-recordable'
import type { TaskRecord } from '../models/task-record' import { TaskRecord } from '../models/task-record'
type RecordId = string type RecordId = string
@@ -42,6 +42,7 @@ export const useTaskRecordStore = defineStore('task-record-store', {
start: ISODate start: ISODate
}) { }) {
this.records[params.recordId].stepRecords[params.stepId] = { this.records[params.recordId].stepRecords[params.stepId] = {
problems: [],
start: params.start start: params.start
} }
}, },
@@ -54,13 +55,22 @@ export const useTaskRecordStore = defineStore('task-record-store', {
} }
stepRecord.end = params.end 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: { getters: {
getTaskRecords() { getTaskRecords() {
return (taskId: string): Recordable[] => return (taskId: string): TaskRecord[] =>
this.taskRecordMaps?.[taskId]?.map( this.taskRecordMaps?.[taskId]?.map((recordId) =>
(recordId) => this.records[recordId] TaskRecord.fromRecordable(this.records[recordId])
) ?? [] ) ?? []
}, },
getStepRecord() { getStepRecord() {