Complete TASK-017 simplified EMOM and per-side entry
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { openLocalDatabase } from './localDatabase.js'
|
||||
import { performanceError, signature } from './performanceModel.js'
|
||||
|
||||
export const performanceKey = (date, period, exerciseId) => `${date}:${period}:${exerciseId}`
|
||||
export const performanceKey = (date, period, exerciseId, format) => `${date}:${period}:${exerciseId}${format === 'emom-total' ? ':emom-total' : ''}`
|
||||
async function transaction(mode, action) {
|
||||
const db = await openLocalDatabase()
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -15,15 +15,15 @@ async function transaction(mode, action) {
|
||||
tx.onerror = tx.onabort = () => { db.close(); reject(new Error('Could not access detailed performance storage. Your changes were not saved.')) }
|
||||
})
|
||||
}
|
||||
export async function readPerformance(date, period, exerciseId) {
|
||||
const record = await transaction('readonly', (store) => store.get(performanceKey(date, period, exerciseId)))
|
||||
export async function readPerformance(date, period, exerciseId, format) {
|
||||
const record = await transaction('readonly', (store) => store.get(performanceKey(date, period, exerciseId, format)))
|
||||
if (record && performanceError(record)) throw new Error('The saved performance record is invalid or unsupported.')
|
||||
return record
|
||||
}
|
||||
export async function writePerformance(record) {
|
||||
const error = performanceError(record)
|
||||
if (error) throw new Error(error)
|
||||
await transaction('readwrite', (store) => store.put(record, performanceKey(record.date, record.period, record.exerciseId)))
|
||||
await transaction('readwrite', (store) => store.put(record, performanceKey(record.date, record.period, record.exerciseId, record.format)))
|
||||
}
|
||||
export async function previousPerformance(date, period, definition, format) {
|
||||
const records = await transaction('readonly', (store) => store.index('exercisePeriodFormat').getAll([definition.id, period, format]))
|
||||
|
||||
Reference in New Issue
Block a user