32 lines
954 B
TypeScript
32 lines
954 B
TypeScript
|
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||
|
|
import { FocusItemsRepository } from './focus-items.repository';
|
||
|
|
import { FocusItem } from './types/focus-item.types';
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class FocusItemsService {
|
||
|
|
constructor(private readonly repository: FocusItemsRepository) {}
|
||
|
|
|
||
|
|
async findAll(): Promise<FocusItem[]> {
|
||
|
|
return this.repository.findAll();
|
||
|
|
}
|
||
|
|
|
||
|
|
async create(dto: any): Promise<FocusItem> {
|
||
|
|
return this.repository.create(dto);
|
||
|
|
}
|
||
|
|
|
||
|
|
async update(id: string, dto: any): Promise<FocusItem> {
|
||
|
|
const item = await this.repository.update(id, dto);
|
||
|
|
if (!item) throw new NotFoundException(`Focus item ${id} not found`);
|
||
|
|
return item;
|
||
|
|
}
|
||
|
|
|
||
|
|
async complete(id: string): Promise<FocusItem> {
|
||
|
|
const item = await this.repository.update(id, {
|
||
|
|
status: 'completed',
|
||
|
|
completedAt: new Date(),
|
||
|
|
});
|
||
|
|
if (!item) throw new NotFoundException(`Focus item ${id} not found`);
|
||
|
|
return item;
|
||
|
|
}
|
||
|
|
}
|