Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 34x 6x 1x 1x 1x | import type { HistoryEntry } from '@/shared/types';
import { historyTable } from '@/entities/history/api';
import { REPOSITORY_FIELDS } from '@/shared/constants';
export const historyRepository = {
async add(entry: HistoryEntry): Promise<void> {
await historyTable.put(entry);
},
async getByProject(projectId: string): Promise<HistoryEntry[]> {
return historyTable
.where(`${REPOSITORY_FIELDS.STATE_PROJECT_ID}`)
.equals(projectId)
.sortBy(`${REPOSITORY_FIELDS.TIMESTAMP}`);
},
async deleteById(id: string): Promise<void> {
await historyTable.where(REPOSITORY_FIELDS.ID).equals(id).delete();
},
async deleteAfterIndex(projectId: string, index: number): Promise<void> {
const all = await this.getByProject(projectId);
const toDelete = all.slice(index + 1);
if (toDelete.length === 0) return;
await Promise.all(toDelete.map((e) => this.deleteById(e.id)));
},
async clearByProject(projectId: string): Promise<void> {
await historyTable
.where(`${REPOSITORY_FIELDS.STATE_PROJECT_ID}`)
.equals(projectId)
.delete();
},
async clearAll(): Promise<void> {
await historyTable.clear();
},
};
|