35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { CreateExpenseDto } from './dto/create-expense.dto';
|
|
import { UpdateExpenseDto } from './dto/update-expense.dto';
|
|
import { ExpenseDataService } from './expense-data.service';
|
|
import { Expense } from './entities/expense.entity';
|
|
|
|
@Injectable()
|
|
export class ExpensesService {
|
|
public constructor(private expenseDataService: ExpenseDataService) { }
|
|
|
|
public async findAll(): Promise<Expense[]> {
|
|
return await this.expenseDataService.getAll();
|
|
}
|
|
|
|
public async findById(id: string): Promise<Expense> {
|
|
const expense = await this.expenseDataService.getById(id);
|
|
if (!expense) {
|
|
throw new Error('No expense found');
|
|
}
|
|
|
|
return expense;
|
|
}
|
|
|
|
public async create(expense: CreateExpenseDto): Promise<Expense> {
|
|
return await this.expenseDataService.create(expense);
|
|
}
|
|
|
|
public async update(expense: UpdateExpenseDto): Promise<Expense> {
|
|
return await this.expenseDataService.update(expense);
|
|
}
|
|
|
|
public async remove(id: string): Promise<void> {
|
|
await this.expenseDataService.delete(id);
|
|
}
|
|
}
|