All files / src/entities/project/api project.repository.ts

87.5% Statements 7/8
100% Branches 0/0
85.71% Functions 6/7
87.5% Lines 7/8

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                26x   3x       5x               10x       16x       4x       1x      
import type { Project } from '@/shared/types';
import { projectTable } from './project.db';
import { REPOSITORY_FIELDS } from '@/shared/constants';
 
/**
 * Repository layer for project entity.
 * Performs CRUD operations on the Dexie table.
 */
export const projectRepository = {
	async getAll(): Promise<Project[]> {
		return projectTable.orderBy(REPOSITORY_FIELDS.UPDATED_AT).reverse().toArray();
	},
 
	async getById(id: string): Promise<Project | undefined> {
		return projectTable.get(id);
	},
 
	async exists(id: string): Promise<boolean> {
		return Boolean(await projectTable.get(id));
	},
 
	async findByName(name: string): Promise<Project | undefined> {
		return projectTable.where(REPOSITORY_FIELDS.NAME).equalsIgnoreCase(name).first();
	},
 
	async add(project: Project): Promise<void> {
		await projectTable.put(project);
	},
 
	async update(id: string, changes: Partial<Project>): Promise<void> {
		await projectTable.update(id, changes);
	},
 
	async remove(id: string): Promise<void> {
		await projectTable.delete(id);
	},
};