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 40 41 42 43 44 | 35x 6x 16x 1x 2x 21x 3x 4x | import type { Layer } from '@/shared/types';
import { layerTable } from '@/entities/layer/api';
import { REPOSITORY_FIELDS } from '@/shared/constants';
export const layerRepository = {
async getById(id: string): Promise<Layer | undefined> {
return layerTable.get(id);
},
async getAllByProject(projectId: string): Promise<Layer[]> {
return layerTable
.where(`${REPOSITORY_FIELDS.PROJECT_ID}`)
.equals(projectId)
.sortBy(`${REPOSITORY_FIELDS.Z_INDEX}`);
},
async getMaxZIndex(projectId: string): Promise<number> {
const layers = await layerTable
.where(`${REPOSITORY_FIELDS.PROJECT_ID}`)
.equals(projectId)
.toArray();
return layers.length ? Math.max(...layers.map((l) => l.zIndex)) : 0;
},
async add(layer: Layer): Promise<void> {
await layerTable.put(layer);
},
async update(id: string, changes: Partial<Layer>): Promise<void> {
await layerTable.update(id, changes);
},
async remove(id: string): Promise<void> {
await layerTable.delete(id);
},
async removeByProject(projectId: string): Promise<void> {
await layerTable
.where(`${REPOSITORY_FIELDS.PROJECT_ID}`)
.equals(projectId)
.delete();
},
};
|