Added automation

This commit is contained in:
2026-09-20 14:38:17 +02:00
parent daa4bbd028
commit c9c524ff2a
13 changed files with 489 additions and 28 deletions

View File

@@ -17,6 +17,9 @@ import { DAY, HOUR, localDateKey } from './time.js';
* @property {'panier'|'restaurant'|null} lunchType
* @property {string|null} restaurant
* @property {number|null} closePromptedTs
* @property {boolean} [autoLunchHandled]
* @property {number|null} [autoLunchEndTs]
* @property {boolean} [lunchManual]
*/
/**
@@ -32,6 +35,7 @@ import { DAY, HOUR, localDateKey } from './time.js';
* @property {string|null} client
* @property {number} startTs
* @property {number|null} endTs
* @property {boolean} [automatic] true only for unconfirmed automatic entries
*/
/**
@@ -167,7 +171,7 @@ export function getEntries(dateKey) {
*
* @param {string} dateKey
* @param {number} ts
* @param {Pick<EntryRecord, 'kind'|'task'|'client'>|null} next
* @param {(Pick<EntryRecord, 'kind'|'task'|'client'> & {automatic?: boolean})|null} next
* Pass null to only close the running entry (end of day).
* @param {number|null} [expectedId] running entry observed by the action's caller
* @returns {Promise<number|null>} id of the new entry
@@ -200,7 +204,7 @@ export function closeAndStart(dateKey, ts, next, expectedId) {
}
export function patchEntry(id, patch) {
return db.entries.update(id, patch);
return db.entries.update(id, { ...patch, automatic: false });
}
/**
@@ -226,8 +230,8 @@ export function setEntryStart(id, ts, now = Date.now()) {
const upper = entry.endTs ?? now;
const stored = Math.min(Math.max(ts, lower), upper);
await db.entries.update(entry.id, { startTs: stored });
if (prev) await db.entries.update(prev.id, { endTs: stored });
await db.entries.update(entry.id, { startTs: stored, ...(entry.automatic ? { automatic: false } : {}) });
if (prev) await db.entries.update(prev.id, { endTs: stored, ...(prev.automatic ? { automatic: false } : {}) });
else await db.days.update(entry.date, { startedTs: stored });
return stored;