added expenses resource
This commit is contained in:
parent
c6434de89d
commit
78c312f279
27 changed files with 310 additions and 86 deletions
34
src/expenses/expense-data.service.ts
Normal file
34
src/expenses/expense-data.service.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Expense } from './entities/expense.entity';
|
||||
import { UpdateExpenseDto } from './dto/update-expense.dto';
|
||||
import { CreateExpenseDto } from './dto/create-expense.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ExpenseDataService {
|
||||
private expenses: Repository<Expense>;
|
||||
|
||||
public constructor(private dataSource: DataSource) {
|
||||
this.expenses = this.dataSource.getRepository(Expense);
|
||||
}
|
||||
|
||||
public async getAll(): Promise<Expense[]> {
|
||||
return await this.expenses.find();
|
||||
}
|
||||
|
||||
public async getById(id: string): Promise<Expense | null> {
|
||||
return await this.expenses.findOneBy({ id });
|
||||
}
|
||||
|
||||
public async create(expense: CreateExpenseDto): Promise<Expense> {
|
||||
return await this.expenses.save(expense);
|
||||
}
|
||||
|
||||
public async update(expense: UpdateExpenseDto): Promise<Expense> {
|
||||
return await this.expenses.save(expense);
|
||||
}
|
||||
|
||||
public async delete(id: string): Promise<void> {
|
||||
await this.expenses.delete({ id });
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue