implemented all controller/service verbs

This commit is contained in:
Joe Arndt 2025-12-11 22:33:29 -06:00
parent 085e84b086
commit f150fe84f2
9 changed files with 246 additions and 65 deletions

View file

@ -1,19 +1,24 @@
import { PartialType } from '@nestjs/mapped-types';
export class CreateExpenseDto {
year: string;
month: string;
day: string;
date: Date;
cents: number;
category: string;
merchant: string;
subcategory: string[];
tags: string[];
categoryId: string;
merchantId?: string;
subcategoryIds?: string[];
tagIds?: string[];
description?: string;
}
export class UpdateExpenseDto extends PartialType(CreateExpenseDto) { }
export class UpdateExpenseDto extends PartialType(CreateExpenseDto) {}
export class GetExpenseDto extends CreateExpenseDto{
id: number;
export class GetExpenseDto {
id: string;
date: Date;
cents: number;
category: string;
merchant?: string;
subcategories?: string[];
tags?: string[];
description?: string;
}

View file

@ -1,32 +1,30 @@
export class Expense {
id: number;
year: string;
month: string;
day: string;
cents: number;
category: Category;
subcategory?: SubCategory[];
merchant?: Merchant;
tags?: Tag[];
description?: string;
id: string;
date: Date;
cents: number;
categoryId: string;
merchantId?: string;
subcategoryIds: string[];
tagIds: string[];
description?: string;
}
export class Category {
id: number;
category: string;
id: string;
category: string;
}
export class SubCategory {
id: number;
subcategory: string;
id: string;
subcategory: string;
}
export class Merchant {
id: number;
merchant: string;
id: string;
merchant: string;
}
export class Tag {
id: number;
tag: string;
id: string;
tag: string;
}

View file

@ -1,6 +1,6 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { Controller, Get, Post, Body, Patch, Param, Delete, NotFoundException, HttpCode } from '@nestjs/common';
import { ExpensesService } from '../../services/expenses.service';
import { CreateExpenseDto, GetExpenseDto, UpdateExpenseDto } from './expense.dto';
import { CreateExpenseDto, UpdateExpenseDto } from './expense.dto';
@Controller('expenses')
export class ExpensesController {
@ -12,22 +12,33 @@ export class ExpensesController {
}
@Get()
findAll(): GetExpenseDto[] {
findAll() {
return this.expensesService.findAll();
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.expensesService.findOne(+id);
const expense = this.expensesService.findOne(id);
if (!expense) {
throw new NotFoundException();
}
return expense;
}
// @Patch(':id')
// update(@Param('id') id: string, @Body() updateExpenseDto: UpdateExpenseDto) {
// return this.expensesService.update(+id, updateExpenseDto);
// }
//
// @Delete(':id')
// remove(@Param('id') id: string) {
// return this.expensesService.remove(+id);
// }
@Patch(':id')
update(@Param('id') id: string, @Body() updateExpenseDto: UpdateExpenseDto) {
const expense = this.expensesService.update(id, updateExpenseDto);
if (!expense) {
throw new NotFoundException();
}
return expense;
}
@Delete(':id')
@HttpCode(204)
remove(@Param('id') id: string) {
return this.expensesService.remove(id);
}
}