added expenses resource
This commit is contained in:
parent
c6434de89d
commit
78c312f279
27 changed files with 310 additions and 86 deletions
35
src/expenses/expenses.service.ts
Normal file
35
src/expenses/expenses.service.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue